Title: [148721] trunk/Source/_javascript_Core
- Revision
- 148721
- Author
- benja...@webkit.org
- Date
- 2013-04-18 18:52:50 -0700 (Thu, 18 Apr 2013)
Log Message
Use StringJoiner to create the JSString of arrayProtoFuncToString
https://bugs.webkit.org/show_bug.cgi?id=114779
Patch by Benjamin Poulain <bpoul...@apple.com> on 2013-04-18
Reviewed by Geoffrey Garen.
The function arrayProtoFuncToString was just a glorified JSStringJoiner.
This patch replaces it by JSStringJoiner to simplify the code and enjoy any optimization
made on JSStringJoiner.
For some reason, this makes the execution 3.4% faster, despite having almost identical code.
* runtime/ArrayPrototype.cpp:
(JSC::arrayProtoFuncToString):
Modified Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (148720 => 148721)
--- trunk/Source/_javascript_Core/ChangeLog 2013-04-19 01:34:07 UTC (rev 148720)
+++ trunk/Source/_javascript_Core/ChangeLog 2013-04-19 01:52:50 UTC (rev 148721)
@@ -1,3 +1,19 @@
+2013-04-18 Benjamin Poulain <bpoul...@apple.com>
+
+ Use StringJoiner to create the JSString of arrayProtoFuncToString
+ https://bugs.webkit.org/show_bug.cgi?id=114779
+
+ Reviewed by Geoffrey Garen.
+
+ The function arrayProtoFuncToString was just a glorified JSStringJoiner.
+ This patch replaces it by JSStringJoiner to simplify the code and enjoy any optimization
+ made on JSStringJoiner.
+
+ For some reason, this makes the execution 3.4% faster, despite having almost identical code.
+
+ * runtime/ArrayPrototype.cpp:
+ (JSC::arrayProtoFuncToString):
+
2013-04-18 Oliver Hunt <oli...@apple.com>
StackFrame::column() returning bogus value
Modified: trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp (148720 => 148721)
--- trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2013-04-19 01:34:07 UTC (rev 148720)
+++ trunk/Source/_javascript_Core/runtime/ArrayPrototype.cpp 2013-04-19 01:52:50 UTC (rev 148721)
@@ -1,6 +1,6 @@
/*
* Copyright (C) 1999-2000 Harri Porten (por...@kde.org)
- * Copyright (C) 2003, 2007, 2008, 2009, 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2003, 2007, 2008, 2009, 2011, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2003 Peter Kelly (p...@post.com)
* Copyright (C) 2006 Alexey Proskuryakov (a...@nypop.com)
*
@@ -304,64 +304,27 @@
if (JSValue earlyReturnValue = checker.earlyReturnValue())
return JSValue::encode(earlyReturnValue);
- unsigned totalSize = length ? length - 1 : 0;
- Vector<RefPtr<StringImpl>, 256> strBuffer(length);
- bool allStrings8Bit = true;
-
+ String separator(",", String::ConstructFromLiteral);
+ JSStringJoiner stringJoiner(separator, length);
for (unsigned k = 0; k < length; k++) {
JSValue element;
if (thisObj->canGetIndexQuickly(k))
element = thisObj->getIndexQuickly(k);
- else
+ else {
element = thisObj->get(exec, k);
-
- if (element.isUndefinedOrNull())
- continue;
-
- String str = element.toWTFString(exec);
- strBuffer[k] = str.impl();
- totalSize += str.length();
- allStrings8Bit = allStrings8Bit && str.is8Bit();
-
- if (!strBuffer.data()) {
- throwOutOfMemoryError(exec);
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
}
-
- if (exec->hadException())
- break;
- }
- if (!totalSize)
- return JSValue::encode(jsEmptyString(exec));
- if (allStrings8Bit) {
- Vector<LChar> buffer;
- buffer.reserveCapacity(totalSize);
- if (!buffer.data())
- return JSValue::encode(throwOutOfMemoryError(exec));
-
- for (unsigned i = 0; i < length; i++) {
- if (i)
- buffer.append(',');
- if (RefPtr<StringImpl> rep = strBuffer[i])
- buffer.append(rep->characters8(), rep->length());
- }
- ASSERT(buffer.size() == totalSize);
- return JSValue::encode(jsString(exec, String::adopt(buffer)));
- }
+ if (element.isUndefinedOrNull())
+ stringJoiner.append(String());
+ else
+ stringJoiner.append(element.toWTFString(exec));
- Vector<UChar> buffer;
- buffer.reserveCapacity(totalSize);
- if (!buffer.data())
- return JSValue::encode(throwOutOfMemoryError(exec));
-
- for (unsigned i = 0; i < length; i++) {
- if (i)
- buffer.append(',');
- if (RefPtr<StringImpl> rep = strBuffer[i])
- buffer.append(rep->characters(), rep->length());
+ if (exec->hadException())
+ return JSValue::encode(jsUndefined());
}
- ASSERT(buffer.size() == totalSize);
- return JSValue::encode(jsString(exec, String::adopt(buffer)));
+ return JSValue::encode(stringJoiner.build(exec));
}
EncodedJSValue JSC_HOST_CALL arrayProtoFuncToLocaleString(ExecState* exec)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes