Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (184616 => 184617)
--- trunk/Source/_javascript_Core/ChangeLog 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/_javascript_Core/ChangeLog 2015-05-20 05:57:55 UTC (rev 184617)
@@ -1,5 +1,22 @@
2015-05-19 Andreas Kling <[email protected]>
+ Give StringView a utf8() API.
+ <https://webkit.org/b/145201>
+
+ Reviewed by Anders Carlsson.
+
+ Use JSString::view() in a few places where we couldn't before due to StringView
+ lacking a utf8() API. This is a minor speed-up on Kraken's crypto subtests,
+ which like to call encode() with substring JSStrings.
+
+ * jsc.cpp:
+ (functionPrint):
+ (functionDebug):
+ * runtime/JSGlobalObjectFunctions.cpp:
+ (JSC::encode):
+
+2015-05-19 Andreas Kling <[email protected]>
+
[JSC] Speed up URL encode/decode by using bitmaps instead of strchr().
<https://webkit.org/b/145115>
Modified: trunk/Source/_javascript_Core/jsc.cpp (184616 => 184617)
--- trunk/Source/_javascript_Core/jsc.cpp 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/_javascript_Core/jsc.cpp 2015-05-20 05:57:55 UTC (rev 184617)
@@ -690,7 +690,7 @@
if (i)
putchar(' ');
- printf("%s", exec->uncheckedArgument(i).toString(exec)->value(exec).utf8().data());
+ printf("%s", exec->uncheckedArgument(i).toString(exec)->view(exec).utf8().data());
}
putchar('\n');
@@ -711,7 +711,7 @@
EncodedJSValue JSC_HOST_CALL functionDebug(ExecState* exec)
{
- fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec)->value(exec).utf8().data());
+ fprintf(stderr, "--> %s\n", exec->argument(0).toString(exec)->view(exec).utf8().data());
return JSValue::encode(jsUndefined());
}
Modified: trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp (184616 => 184617)
--- trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/_javascript_Core/runtime/JSGlobalObjectFunctions.cpp 2015-05-20 05:57:55 UTC (rev 184617)
@@ -64,7 +64,7 @@
static JSValue encode(ExecState* exec, const Bitmap<256>& doNotEscape)
{
- CString cstr = exec->argument(0).toString(exec)->value(exec).utf8(StrictConversion);
+ CString cstr = exec->argument(0).toString(exec)->view(exec).utf8(StrictConversion);
if (!cstr.data())
return exec->vm().throwException(exec, createURIError(exec, ASCIILiteral("String contained an illegal UTF-16 sequence.")));
Modified: trunk/Source/WTF/ChangeLog (184616 => 184617)
--- trunk/Source/WTF/ChangeLog 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/WTF/ChangeLog 2015-05-20 05:57:55 UTC (rev 184617)
@@ -1,3 +1,20 @@
+2015-05-19 Andreas Kling <[email protected]>
+
+ Give StringView a utf8() API.
+ <https://webkit.org/b/145201>
+
+ Reviewed by Anders Carlsson
+
+ Added an LChar version of StringImpl::utf8ForCharacters() and use that to give
+ StringView a utf8() API just like String has.
+
+ * wtf/text/StringImpl.cpp:
+ (WTF::StringImpl::utf8ForCharacters):
+ * wtf/text/StringImpl.h:
+ * wtf/text/StringView.cpp:
+ (WTF::StringView::utf8):
+ * wtf/text/StringView.h:
+
2015-05-19 Yusuke Suzuki <[email protected]>
Move AtomicStringImpl table related operations from AtomicString to AtomicStringImpl
Modified: trunk/Source/WTF/wtf/text/StringImpl.cpp (184616 => 184617)
--- trunk/Source/WTF/wtf/text/StringImpl.cpp 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/WTF/wtf/text/StringImpl.cpp 2015-05-20 05:57:55 UTC (rev 184617)
@@ -2198,6 +2198,20 @@
return true;
}
+CString StringImpl::utf8ForCharacters(const LChar* characters, unsigned length)
+{
+ if (!length)
+ return CString("", 0);
+ if (length > std::numeric_limits<unsigned>::max() / 3)
+ return CString();
+ Vector<char, 1024> bufferVector(length * 3);
+ char* buffer = bufferVector.data();
+ const LChar* source = characters;
+ ConversionResult result = convertLatin1ToUTF8(&source, source + length, &buffer, buffer + bufferVector.size());
+ ASSERT_UNUSED(result, result != targetExhausted); // (length * 3) should be sufficient for any conversion
+ return CString(bufferVector.data(), buffer - bufferVector.data());
+}
+
CString StringImpl::utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode mode)
{
if (!length)
Modified: trunk/Source/WTF/wtf/text/StringImpl.h (184616 => 184617)
--- trunk/Source/WTF/wtf/text/StringImpl.h 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/WTF/wtf/text/StringImpl.h 2015-05-20 05:57:55 UTC (rev 184617)
@@ -512,6 +512,7 @@
bool isSubString() const { return bufferOwnership() == BufferSubstring; }
#endif
+ static WTF_EXPORT_STRING_API CString utf8ForCharacters(const LChar* characters, unsigned length);
static WTF_EXPORT_STRING_API CString utf8ForCharacters(const UChar* characters, unsigned length, ConversionMode = LenientConversion);
WTF_EXPORT_STRING_API CString utf8ForRange(unsigned offset, unsigned length, ConversionMode = LenientConversion) const;
WTF_EXPORT_STRING_API CString utf8(ConversionMode = LenientConversion) const;
Modified: trunk/Source/WTF/wtf/text/StringView.cpp (184616 => 184617)
--- trunk/Source/WTF/wtf/text/StringView.cpp 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/WTF/wtf/text/StringView.cpp 2015-05-20 05:57:55 UTC (rev 184617)
@@ -30,9 +30,12 @@
#include <mutex>
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
+#include <wtf/unicode/UTF8.h>
namespace WTF {
+using namespace Unicode;
+
bool StringView::containsIgnoringASCIICase(const StringView& matchString) const
{
return findIgnoringASCIICase(matchString) != notFound;
@@ -84,6 +87,15 @@
return equalIgnoringASCIICase(a.characters16(), b, bLength);
}
+CString StringView::utf8(ConversionMode mode) const
+{
+ if (isNull())
+ return CString("", 0);
+ if (is8Bit())
+ return StringImpl::utf8ForCharacters(characters8(), length());
+ return StringImpl::utf8ForCharacters(characters16(), length(), mode);
+}
+
#if CHECK_STRINGVIEW_LIFETIME
// Manage reference count manually so UnderlyingString does not need to be defined in the header.
Modified: trunk/Source/WTF/wtf/text/StringView.h (184616 => 184617)
--- trunk/Source/WTF/wtf/text/StringView.h 2015-05-20 05:41:13 UTC (rev 184616)
+++ trunk/Source/WTF/wtf/text/StringView.h 2015-05-20 05:57:55 UTC (rev 184617)
@@ -30,6 +30,8 @@
#include <wtf/Forward.h>
#include <wtf/RetainPtr.h>
#include <wtf/Vector.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/ConversionMode.h>
#include <wtf/text/LChar.h>
#include <wtf/text/StringCommon.h>
@@ -96,6 +98,8 @@
WTF_EXPORT_STRING_API RetainPtr<NSString> createNSStringWithoutCopying() const;
#endif
+ WTF_EXPORT_STRING_API CString utf8(ConversionMode = LenientConversion) const;
+
class UpconvertedCharacters;
UpconvertedCharacters upconvertedCharacters() const;