S
Sean Kenwrick
pembed2003 said:"Sean Kenwrick" <[email protected]> wrote in message
Do you mean memcmp() here instead? Yes I think memcpy is faster than
strcmp or strncmp but I need to find out the longer string and pass in
the lenght of that. Otherwise, something like:
char* s1 = "auto";
char* s2 = "auto insurance";
memcmp(s1,s2,strlen(s1));
will return 0 which isn't. I will need to do the extra work like:
int l1 = strlen(s1);
int l2 = strlen(s2);
memcmp(s1,s2,l1 > l2 ? l1 : l2);
Do you think that will be faster than a strcmp or strncmp?
You need to examine your code for data-caching possibilities. What I mean
by this is that you evaluate a value at some stage which you keep and use
multiple times later on. In this case the important value is the length
of the strings. From a previous post it looks like you are evaluating
hash_keys() prior to posting keys into your lookup table - it seems that
this function is a likely candidate for calculating the length of the string
with little overhead (e.g save the original pointer and use pointer
arithmetic at the end to calculate the strlen()). You could then store
the length along with the other information in your lookup table.
Then you only need to do a memcmp() if the strings are of equal length, and
you already have the string lengths calculated if you do need to call
memcmp()...
Sean