RESOLVED FIXED 53266
Add WTFString method to compare equality with Vector<UChar>
https://bugs.webkit.org/show_bug.cgi?id=53266
Summary Add WTFString method to compare equality with Vector<UChar>
Adam Barth
Reported 2011-01-27 16:17:26 PST
Add WTFString method to compare equality with Vector<UChar>
Attachments
Patch (2.48 KB, patch)
2011-01-27 16:18 PST, Adam Barth
eric: review+
Adam Barth
Comment 1 2011-01-27 16:18:35 PST
Eric Seidel (no email)
Comment 2 2011-01-27 16:59:49 PST
Comment on attachment 80373 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=80373&action=review Seems OK. > Source/JavaScriptCore/wtf/text/StringImpl.h:366 > + if (!a.size()) > + return true; > + return !memcmp(a.data(), b->characters(), b->length()); Is calling memcmp with length = 0 OK? If so then you don't need the !a.size() check.
Adam Barth
Comment 3 2011-01-27 17:04:14 PST
Comment on attachment 80373 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=80373&action=review >> Source/JavaScriptCore/wtf/text/StringImpl.h:366 >> + if (!a.size()) >> + return true; >> + return !memcmp(a.data(), b->characters(), b->length()); > > Is calling memcmp with length = 0 OK? If so then you don't need the !a.size() check. Sounds dodgy: http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-07/0109.html
Darin Adler
Comment 4 2011-01-27 17:45:14 PST
(In reply to comment #3) > > Is calling memcmp with length = 0 OK? If so then you don't need the !a.size() check. > > Sounds dodgy: > http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2004-07/0109.html Why the FUD? memcpy with length == 0 is definitely OK!
Darin Adler
Comment 5 2011-01-27 17:45:27 PST
(In reply to comment #4) > Why the FUD? memcpy with length == 0 is definitely OK! I mean memcmp.
Adam Barth
Comment 6 2011-01-27 17:55:53 PST
> Why the FUD? memcpy with length == 0 is definitely OK! Even if one of the pointers is NULL?
Darin Adler
Comment 7 2011-01-27 18:03:31 PST
(In reply to comment #6) > > Why the FUD? memcmp with length == 0 is definitely OK! > > Even if one of the pointers is NULL? In practice, yes. I am pretty damned sure of this. And I think we rely on it. But the C standard does use wording that makes it seem a little ambiguous.
Adam Barth
Comment 8 2011-01-27 18:15:10 PST
Okiedokes. Thanks.
Adam Barth
Comment 9 2011-01-27 18:21:05 PST
WebKit Review Bot
Comment 10 2011-01-27 19:47:31 PST
WebKit Review Bot
Comment 11 2011-01-27 20:27:11 PST
http://trac.webkit.org/changeset/76894 might have broken GTK Linux 64-bit Debug
Note You need to log in before you can comment on or make changes to this bug.