Title: [214272] trunk
- Revision
- 214272
- Author
- [email protected]
- Date
- 2017-03-22 13:07:21 -0700 (Wed, 22 Mar 2017)
Log Message
[JSC] Use jsNontrivialString for Number toString operations
https://bugs.webkit.org/show_bug.cgi?id=169965
Reviewed by Mark Lam.
JSTests:
* stress/to-string-int32.js: Added.
(shouldBe):
(toString10):
(expected):
Source/_javascript_Core:
After single character check, produced string is always longer than 1.
Thus, we can use jsNontrivialString.
* runtime/NumberPrototype.cpp:
(JSC::int32ToStringInternal):
Modified Paths
Added Paths
Diff
Modified: trunk/JSTests/ChangeLog (214271 => 214272)
--- trunk/JSTests/ChangeLog 2017-03-22 19:50:09 UTC (rev 214271)
+++ trunk/JSTests/ChangeLog 2017-03-22 20:07:21 UTC (rev 214272)
@@ -1,3 +1,15 @@
+2017-03-22 Yusuke Suzuki <[email protected]>
+
+ [JSC] Use jsNontrivialString for Number toString operations
+ https://bugs.webkit.org/show_bug.cgi?id=169965
+
+ Reviewed by Mark Lam.
+
+ * stress/to-string-int32.js: Added.
+ (shouldBe):
+ (toString10):
+ (expected):
+
2017-03-22 JF Bastien <[email protected]>
WebAssembly: test module namespace object for WebAssembly.Instance
Added: trunk/JSTests/stress/to-string-int32.js (0 => 214272)
--- trunk/JSTests/stress/to-string-int32.js (rev 0)
+++ trunk/JSTests/stress/to-string-int32.js 2017-03-22 20:07:21 UTC (rev 214272)
@@ -0,0 +1,59 @@
+function shouldBe(actual, expected)
+{
+ if (actual !== expected)
+ throw new Error(`bad value: expected:(${expected}),actual:(${actual})`);
+}
+
+function toString(value, radix)
+{
+ return value.toString(radix);
+}
+noInline(toString);
+
+function toString10(value)
+{
+ return `${value}`;
+}
+noInline(toString10);
+
+function expected(num, radix)
+{
+ let characters = "0123456789abcdefghijklmnopqrstuvwxyz";
+ let result = "";
+ let negative = false;
+ if (num < 0) {
+ negative = true;
+ num = -num;
+ }
+
+ do {
+ const index = num % radix;
+ result = characters[index] + result;
+ num = (num - index) / radix;
+ } while (num);
+
+ if (negative)
+ return '-' + result;
+ return result;
+}
+
+for (var i = 0; i < 1e4; ++i) {
+ toString(i, 10);
+ toString(i, 36);
+ toString10(i);
+}
+
+for (var radix = 2; radix < 37; ++radix) {
+ for (var lessThanRadix = -2000; lessThanRadix < radix; ++lessThanRadix)
+ shouldBe(toString(lessThanRadix, radix), expected(lessThanRadix, radix));
+ for (var greaterThanRadix = radix; greaterThanRadix < 2000; ++greaterThanRadix)
+ shouldBe(toString(greaterThanRadix, radix), expected(greaterThanRadix, radix));
+}
+
+{
+ var radix = 10;
+ for (var lessThanRadix = -2000; lessThanRadix < radix; ++lessThanRadix)
+ shouldBe(toString10(lessThanRadix), expected(lessThanRadix, radix));
+ for (var greaterThanRadix = radix; greaterThanRadix < 2000; ++greaterThanRadix)
+ shouldBe(toString10(greaterThanRadix), expected(greaterThanRadix, radix));
+}
Modified: trunk/Source/_javascript_Core/ChangeLog (214271 => 214272)
--- trunk/Source/_javascript_Core/ChangeLog 2017-03-22 19:50:09 UTC (rev 214271)
+++ trunk/Source/_javascript_Core/ChangeLog 2017-03-22 20:07:21 UTC (rev 214272)
@@ -1,3 +1,16 @@
+2017-03-22 Yusuke Suzuki <[email protected]>
+
+ [JSC] Use jsNontrivialString for Number toString operations
+ https://bugs.webkit.org/show_bug.cgi?id=169965
+
+ Reviewed by Mark Lam.
+
+ After single character check, produced string is always longer than 1.
+ Thus, we can use jsNontrivialString.
+
+ * runtime/NumberPrototype.cpp:
+ (JSC::int32ToStringInternal):
+
2017-03-22 JF Bastien <[email protected]>
WebAssembly: name ExecState consistently
Modified: trunk/Source/_javascript_Core/runtime/NumberPrototype.cpp (214271 => 214272)
--- trunk/Source/_javascript_Core/runtime/NumberPrototype.cpp 2017-03-22 19:50:09 UTC (rev 214271)
+++ trunk/Source/_javascript_Core/runtime/NumberPrototype.cpp 2017-03-22 20:07:21 UTC (rev 214272)
@@ -499,7 +499,7 @@
return radix;
}
-static inline JSString* int32ToStringInternal(VM& vm, int32_t value, int32_t radix)
+static ALWAYS_INLINE JSString* int32ToStringInternal(VM& vm, int32_t value, int32_t radix)
{
ASSERT(!(radix < 2 || radix > 36));
// A negative value casted to unsigned would be bigger than 36 (the max radix).
@@ -509,11 +509,10 @@
return vm.smallStrings.singleCharacterString(radixDigits[value]);
}
- if (radix == 10) {
- return jsString(&vm, vm.numericStrings.add(value));
- }
+ if (radix == 10)
+ return jsNontrivialString(&vm, vm.numericStrings.add(value));
- return jsString(&vm, toStringWithRadix(value, radix));
+ return jsNontrivialString(&vm, toStringWithRadix(value, radix));
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes