Bug 46509 - Add operator == for AtomicString and Vector<Uchar>
Summary: Add operator == for AtomicString and Vector<Uchar>
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Erik Arvidsson
URL:
Keywords:
Depends on:
Blocks: 20709
  Show dependency treegraph
 
Reported: 2010-09-24 14:13 PDT by Erik Arvidsson
Modified: 2010-09-27 13:43 PDT (History)
4 users (show)

See Also:


Attachments
Patch (3.24 KB, patch)
2010-09-24 14:28 PDT, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (2.46 KB, patch)
2010-09-24 18:38 PDT, Erik Arvidsson
no flags Details | Formatted Diff | Diff
Patch (3.61 KB, patch)
2010-09-27 11:46 PDT, Erik Arvidsson
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Arvidsson 2010-09-24 14:13:55 PDT
Add operator == for AtomicString and Vector<Uchar>
Comment 1 Erik Arvidsson 2010-09-24 14:28:00 PDT
Created attachment 68749 [details]
Patch
Comment 2 Erik Arvidsson 2010-09-24 18:10:58 PDT
Darin suggested that I added this function in bug 20709.
Comment 3 Darin Adler 2010-09-24 18:21:54 PDT
Comment on attachment 68749 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68749&action=review

> JavaScriptCore/wtf/text/AtomicString.cpp:159
> +bool operator==(const AtomicString& a, const Vector<UChar>& b)

Unlike strings, there is no concept of a null vector as distinct from an empty vector, so there should not be code here checking b.data() for null.

> JavaScriptCore/wtf/text/AtomicString.cpp:161
> +    StringImpl* impl = a.impl();

It doesn’t help readability or efficiency to put this into a local variable.

> JavaScriptCore/wtf/text/AtomicString.cpp:163
> +    if ((!impl || !impl->characters()) && !s)

There’s no need to check null impl->characters().

> JavaScriptCore/wtf/text/AtomicString.cpp:167
> +    return equal(impl, s, b.size());

This whole function can just be:

    return a.impl() && equal(a.impl(), b.data(), b.size());

No need for any other null checks.
Comment 4 Erik Arvidsson 2010-09-24 18:38:57 PDT
Created attachment 68799 [details]
Patch
Comment 5 Darin Adler 2010-09-24 18:45:13 PDT
Comment on attachment 68799 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68799&action=review

> JavaScriptCore/wtf/text/AtomicString.h:129
> +inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); }

Oops! This won’t compile. The equal function this calls is inside AtomicString.cpp and private to the cpp file, not exposed to the header at all.
Comment 6 Erik Arvidsson 2010-09-24 18:46:41 PDT
Comment on attachment 68799 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68799&action=review

>> JavaScriptCore/wtf/text/AtomicString.h:129
>> +inline bool operator==(const AtomicString& a, const Vector<UChar>& b) { return a.impl() && equal(a.impl(), b.data(), b.size()); }
> 
> Oops! This won’t compile. The equal function this calls is inside AtomicString.cpp and private to the cpp file, not exposed to the header at all.

Yeah, I apologize for that patch upload. I'm moving it to the cpp and compiling and testing again.
Comment 7 Eric Seidel (no email) 2010-09-24 19:05:12 PDT
Attachment 68799 [details] did not build on mac:
Build output: http://queues.webkit.org/results/4061109
Comment 8 Erik Arvidsson 2010-09-27 11:46:44 PDT
Created attachment 68937 [details]
Patch
Comment 9 Darin Adler 2010-09-27 11:47:34 PDT
Comment on attachment 68937 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68937&action=review

> JavaScriptCore/wtf/text/AtomicString.cpp:158
>  }
> +bool operator==(const AtomicString& a, const Vector<UChar>& b)

There should be a blank line there.

We could use the names "string" and "vector" instead of "a" and "b" here.
Comment 10 Erik Arvidsson 2010-09-27 12:22:40 PDT
Comment on attachment 68937 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=68937&action=review

Thanks for your patience.

>> JavaScriptCore/wtf/text/AtomicString.cpp:158
>> +bool operator==(const AtomicString& a, const Vector<UChar>& b)
> 
> There should be a blank line there.
> 
> We could use the names "string" and "vector" instead of "a" and "b" here.

Done and done.
Comment 11 Erik Arvidsson 2010-09-27 13:43:56 PDT
Committed r68422: <http://trac.webkit.org/changeset/68422>