[webkit-reviews] review granted: [Bug 225890] Use UTF-8 internally from Strings inside SQLiteStatement : [Attachment 428904] Patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon May 17 23:18:25 PDT 2021


Darin Adler <darin at apple.com> has granted Chris Dumez <cdumez at apple.com>'s
request for review:
Bug 225890: Use UTF-8 internally from Strings inside SQLiteStatement
https://bugs.webkit.org/show_bug.cgi?id=225890

Attachment 428904: Patch

https://bugs.webkit.org/attachment.cgi?id=428904&action=review




--- Comment #8 from Darin Adler <darin at apple.com> ---
Comment on attachment 428904
  --> https://bugs.webkit.org/attachment.cgi?id=428904
Patch

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

> Source/WebCore/platform/sql/SQLiteStatement.cpp:120
> +    auto utf8Text = text.utf8();

Seems like we should consider an idiom that uses the characters in place for
all-ASCII strings. No need to make a copy on the heap in that case, and that
may be the common case, and the scan through the characters to check they are
all ASCII is probably efficient enough that it’s an optimization on balance. We
could make a function that returns a structure that sometimes contains a
CString but always contains a const char* pointing to the UTF-8 characters, and
a length. Or we could make a function that takes a lambda and calls it with the
UTF-8 characters and length. Or we can just write it out here:

    CString buffer;
    const char* characters;
    unsigned length;
    if (text.is8Bit() && text.isAllASCII()) {
	characters = reinterpret_cast<const char*>(text.characters8());
	length = text.length();
    } else {
	buffer = text.utf8();
	characters = utf8Buffer.data();
	length = utf8Buffer.length();
    }
    return sqlite3_bind_text(m_statement, index, characters, length,
SQLITE_TRANSIENT);


More information about the webkit-reviews mailing list