Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Unified Diff: src/code-stub-assembler.cc

Issue 2293943002: [builtins] Create StringToNumber helper. (Closed)
Patch Set: Addressed nits. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/code-stub-assembler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/code-stub-assembler.cc
diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc
index 7ec5a88e5610048c7d9f54a990c39a50ea4b92a6..6874e6fb0855edf05e9659404cc8974de24da456 100644
--- a/src/code-stub-assembler.cc
+++ b/src/code-stub-assembler.cc
@@ -2216,6 +2216,31 @@ Node* CodeStubAssembler::StringFromCharCode(Node* code) {
return var_result.value();
}
+Node* CodeStubAssembler::StringToNumber(Node* context, Node* input) {
+ Label runtime(this, Label::kDeferred);
+ Label end(this);
+
+ Variable var_result(this, MachineRepresentation::kTagged);
+
+ // Check if string has a cached array index.
+ Node* hash = LoadNameHashField(input);
+ Node* bit =
+ Word32And(hash, Int32Constant(String::kContainsCachedArrayIndexMask));
+ GotoIf(Word32NotEqual(bit, Int32Constant(0)), &runtime);
+
+ var_result.Bind(SmiTag(BitFieldDecode<String::ArrayIndexValueBits>(hash)));
+ Goto(&end);
+
+ Bind(&runtime);
+ {
+ var_result.Bind(CallRuntime(Runtime::kStringToNumber, context, input));
+ Goto(&end);
+ }
+
+ Bind(&end);
+ return var_result.value();
+}
+
Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift,
uint32_t mask) {
return Word32Shr(Word32And(word32, Int32Constant(mask)),
« no previous file with comments | « src/code-stub-assembler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698