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

Side by Side Diff: src/code-stub-assembler.cc

Issue 2667963002: [stubs] Remove StringIndexOfChar (Closed)
Patch Set: Rebase Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/code-stub-assembler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 #include "src/code-stub-assembler.h" 4 #include "src/code-stub-assembler.h"
5 #include "src/code-factory.h" 5 #include "src/code-factory.h"
6 #include "src/frames-inl.h" 6 #include "src/frames-inl.h"
7 #include "src/frames.h" 7 #include "src/frames.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 3714 matching lines...) Expand 10 before | Expand all | Expand 10 after
3725 Bind(&done_native); 3725 Bind(&done_native);
3726 { 3726 {
3727 IncrementCounter(counters->string_add_native(), 1); 3727 IncrementCounter(counters->string_add_native(), 1);
3728 Goto(&done); 3728 Goto(&done);
3729 } 3729 }
3730 3730
3731 Bind(&done); 3731 Bind(&done);
3732 return result.value(); 3732 return result.value();
3733 } 3733 }
3734 3734
3735 Node* CodeStubAssembler::StringIndexOfChar(Node* context, Node* string,
3736 Node* needle_char, Node* from) {
3737 CSA_ASSERT(this, IsString(string));
3738 Variable var_result(this, MachineRepresentation::kTagged);
3739
3740 Label out(this), runtime(this, Label::kDeferred);
3741
3742 // Let runtime handle non-one-byte {needle_char}.
3743
3744 Node* const one_byte_char_mask = Int32Constant(0xFF);
3745 GotoUnless(
3746 Word32Equal(Word32And(needle_char, one_byte_char_mask), needle_char),
3747 &runtime);
3748
3749 // TODO(jgruber): Handle external and two-byte strings.
3750
3751 Node* const one_byte_seq_mask = Int32Constant(
3752 kIsIndirectStringMask | kExternalStringTag | kStringEncodingMask);
3753 Node* const expected_masked = Int32Constant(kOneByteStringTag);
3754
3755 Node* const string_instance_type = LoadInstanceType(string);
3756 GotoUnless(Word32Equal(Word32And(string_instance_type, one_byte_seq_mask),
3757 expected_masked),
3758 &runtime);
3759
3760 // If we reach this, {string} is a non-indirect, non-external one-byte string.
3761
3762 Node* const length = LoadStringLength(string);
3763 Node* const search_range_length = SmiUntag(SmiSub(length, from));
3764
3765 const int offset = SeqOneByteString::kHeaderSize - kHeapObjectTag;
3766 Node* const begin = IntPtrConstant(offset);
3767 Node* const cursor = IntPtrAdd(begin, SmiUntag(from));
3768 Node* const end = IntPtrAdd(cursor, search_range_length);
3769
3770 var_result.Bind(SmiConstant(Smi::FromInt(-1)));
3771
3772 BuildFastLoop(
3773 cursor, end,
3774 [this, string, needle_char, begin, &var_result, &out](Node* cursor) {
3775 Label next(this);
3776 Node* value = Load(MachineType::Uint8(), string, cursor);
3777 GotoUnless(Word32Equal(value, needle_char), &next);
3778
3779 // Found a match.
3780 Node* index = SmiTag(IntPtrSub(cursor, begin));
3781 var_result.Bind(index);
3782 Goto(&out);
3783
3784 Bind(&next);
3785 },
3786 1, INTPTR_PARAMETERS, IndexAdvanceMode::kPost);
3787 Goto(&out);
3788
3789 Bind(&runtime);
3790 {
3791 Node* const pattern = StringFromCharCode(needle_char);
3792 Node* const result =
3793 CallRuntime(Runtime::kStringIndexOf, context, string, pattern, from);
3794 var_result.Bind(result);
3795 Goto(&out);
3796 }
3797
3798 Bind(&out);
3799 return var_result.value();
3800 }
3801
3802 Node* CodeStubAssembler::StringFromCodePoint(Node* codepoint, 3735 Node* CodeStubAssembler::StringFromCodePoint(Node* codepoint,
3803 UnicodeEncoding encoding) { 3736 UnicodeEncoding encoding) {
3804 Variable var_result(this, MachineRepresentation::kTagged, 3737 Variable var_result(this, MachineRepresentation::kTagged,
3805 EmptyStringConstant()); 3738 EmptyStringConstant());
3806 3739
3807 Label if_isword16(this), if_isword32(this), return_result(this); 3740 Label if_isword16(this), if_isword32(this), return_result(this);
3808 3741
3809 Branch(Uint32LessThan(codepoint, Int32Constant(0x10000)), &if_isword16, 3742 Branch(Uint32LessThan(codepoint, Int32Constant(0x10000)), &if_isword16,
3810 &if_isword32); 3743 &if_isword32);
3811 3744
(...skipping 4597 matching lines...) Expand 10 before | Expand all | Expand 10 after
8409 formatted.c_str(), TENURED); 8342 formatted.c_str(), TENURED);
8410 CallRuntime(Runtime::kGlobalPrint, NoContextConstant(), 8343 CallRuntime(Runtime::kGlobalPrint, NoContextConstant(),
8411 HeapConstant(string)); 8344 HeapConstant(string));
8412 } 8345 }
8413 CallRuntime(Runtime::kDebugPrint, NoContextConstant(), tagged_value); 8346 CallRuntime(Runtime::kDebugPrint, NoContextConstant(), tagged_value);
8414 #endif 8347 #endif
8415 } 8348 }
8416 8349
8417 } // namespace internal 8350 } // namespace internal
8418 } // namespace v8 8351 } // namespace v8
OLDNEW
« 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