RESOLVED FIXED 24979
Avoid type-coercion into AtomicString in AtomicString methods
https://bugs.webkit.org/show_bug.cgi?id=24979
Summary Avoid type-coercion into AtomicString in AtomicString methods
Mike Belshe
Reported 2009-03-31 20:04:24 PDT
When using AtomicString.find() AtomicStirng.contains() AtomicString.startsWith() AtomicString.endsWith() if you pass a const char* string literal, the argument will be coerced into a String, then into an AtomicString, and then ripped out. This causes unnecessary churn on the AtomicString table.
Attachments
bug24979 (3.98 KB, patch)
2009-03-31 20:56 PDT, Mike Belshe
mbelshe: review-
updated patch (2.54 KB, patch)
2009-04-05 15:24 PDT, Mike Belshe
ap: review+
Mike Belshe
Comment 1 2009-03-31 20:56:50 PDT
Mike Belshe
Comment 2 2009-03-31 20:58:34 PDT
Two notes on the patch: a. Document.cpp and FrameTree.cpp needed small changes because they use AtomicString methods which are ambiguous now that we have the new methods plumbed in. b. I could make these methods chain - e.g. have the one which takes the AtomicString argument in turn call the one which takes the string argument. I don't know which style is preferred on the WebKit side. Just let me know if you have a preference.
Alexey Proskuryakov
Comment 3 2009-04-01 00:10:09 PDT
My suggestion was to replace AtomicString methods with String ones, not to add new methods. Unless we're using them with AtomicStrings very often, a string() call here and there should probably be better than having to disambiguate similar methods. What do you think?
Darin Adler
Comment 4 2009-04-01 13:33:17 PDT
Comment on attachment 29155 [details] bug24979 > for (frame = m_thisFrame; frame; frame = frame->tree()->parent()) { > - if (frame->tree()->name().startsWith(framePathPrefix)) > + if (frame->tree()->name().startsWith(String(framePathPrefix))) It would be much better to overload for const char* too rather than adding the explicit casts to String. We don't want to create any destroy String objects either.
Mike Belshe
Comment 5 2009-04-05 15:24:17 PDT
Created attachment 29268 [details] updated patch Removed the versions which take AtomicStrings. startsWith() and endsWith() have no versions which take const char* anyway, so they now take Strings. find() and contains() now offer both const char* and String variants.
Alexey Proskuryakov
Comment 6 2009-04-06 04:04:09 PDT
Comment on attachment 29268 [details] updated patch r=me We should eventually change these methods to take named enum constants instead of booleans for caseSensitive - a call like str.contains("foo", true) is quite confusing, str.contains("foo", CaseSensitive) would be much better. But that's definitely a separate issue.
Darin Adler
Comment 7 2009-04-06 09:01:40 PDT
(In reply to comment #5) > startsWith() and endsWith() > have no versions which take const char* anyway, so they now take Strings. Side note: In my opinion that's a temporary situation. Any time we find ourselves doing a string operation on a const char* constant, I think it's a good optimization technique to add the const char* override to avoid the memory allocation. Similarly, I think we need to come up with an approach that will allow us to do this for substrings and other UChar*/length pairs.
Darin Fisher (:fishd, Google)
Comment 8 2009-04-06 09:11:12 PDT
Darin Adler
Comment 9 2009-04-06 09:11:53 PDT
(In reply to comment #6) > We should eventually change these methods to take named enum constants instead > of booleans for caseSensitive Or use two separate functions for the two variants.
Note You need to log in before you can comment on or make changes to this bug.