Strings are fixed length 8, contain alphanumeric characters and right-padded with spaces.
I.e,
"STRING1 "
"STR2 "
"S "
etc..
I was thinking memcmp might be the fastest here?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you ensure that the strings are aligned on an 8-byte boundary via compiler-specific attributes, you can do:
Then
a == bshould yield to a single 64-bit instruction.Or, if they are just constant immutable strings (stored in a read-only area of the process), you can go on with comparing the
const char *pointers themselves. It’s still a reliable test since a string literal that appears twice in the current translation unit should refer to the same memory: