[Webkit-unassigned] [Bug 45594] Add AtomicString::fromUTF8
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Sun Sep 12 12:30:37 PDT 2010
https://bugs.webkit.org/show_bug.cgi?id=45594
--- Comment #7 from Patrick R. Gansterer <paroga at paroga.com> 2010-09-12 12:30:37 PST ---
(In reply to comment #6)
> (From update of attachment 67334 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=67334&action=prettypatch
>
> I don't get it. Is this more efficient than making a string and then converting that to an atomic string? Maybe it saves you a memcpy in the case where you have multibyte characters?
XMLParser will uses the version witout a explicit length most of the time. Ther we can calcualte the hash, utf8length and utf16 length in one step:
+AtomicString AtomicString::fromUTF8(const char* characters)
+{
+ if (!characters)
+ return AtomicString();
+
+ HashAndUTF8Characters buffer;
+ buffer.characters = characters;
+ buffer.string = 0;
+
+ if (!calculateHashAndLength(characters, buffer.hash, buffer.lengthUTF8, buffer.lengthUTF16))
+ return AtomicString(); // characters contains invalid UTF-8 characters.
+
+ pair<HashSet<StringImpl*>::iterator, bool> addResult = stringTable().add<HashAndUTF8Characters, HashAndUTF8CharactersTranslator>(buffer);
+
+ // If the string is newly-translated, then we need to adopt it.
+ // The boolean in the pair tells us if that is so.
+ AtomicString atomicString;
+ atomicString.m_string = addResult.second ? adoptRef(*addResult.first) : *addResult.first;
+ return atomicString;
+}
This will avoid unnecessary operations, but requires additonal changes to the stringHash and UTF8 functions.
I'd like to commit this in a first step to start using the "new API" in XMLParser.
--
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the webkit-unassigned
mailing list