In KURL, we frequently compare very short strings, like the scheme and port. Currently, we use strncmp(), we could just compare char by char and let the compiler inline everything.
Created attachment 121613 [details] Patch
Comment on attachment 121613 [details] Patch You should be able to do all of this without hard-coding the lengths of the arrays. template<size_t bLength> static inline bool equal(const char* a, const char b[bLength]) Try it.
Comment on attachment 121613 [details] Patch I'll update later this week, I am busy with another bug atm :(
Created attachment 122562 [details] Patch
The template "template<size_t bLength> static inline bool equal(const char* a, const char b[bLength])" never matched. I read online to use a reference to the array, and this time the compiler match the template.
Created attachment 124046 [details] Patch
Comment on attachment 124046 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=124046&action=review > Source/WebCore/platform/KURL.cpp:1079 > +template<size_t referenceLength> > +static inline bool equal(const char* str, size_t length, const char (&reference)[referenceLength]) > +{ > + return length == referenceLength && equal(str, reference); > } This compares two strings. It seems a little strange that the first string is named “str” with length “length” and the second is named “reference” with name “referenceLength”. I would just name them “a” and “b”, or “stringA” and “stringB”, and “lengthA” and “lengthB”, or something like that.
> This compares two strings. It seems a little strange that the first string is named “str” with length “length” and the second is named “reference” with name “referenceLength”. I would just name them “a” and “b”, or “stringA” and “stringB”, and “lengthA” and “lengthB”, or something like that. Stricto sensu, it is comparing the string to an (reference) const array, that is why I had chosen the name "reference". I do not mind updating that :) Thanks for the review!
For reference, I still don't think it's necessary to declare the strings as character arrays, just make equals handle the trailing null character.
Committed r106025: <http://trac.webkit.org/changeset/106025>
(In reply to comment #9) > For reference, I still don't think it's necessary to declare the strings as character arrays, just make equals handle the trailing null character. Right, we could easily do it that way which would look a little nicer.
Comment on attachment 124046 [details] Patch Clearing useless flag.