OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 ASSERT(previous_index >= 0); | 113 ASSERT(previous_index >= 0); |
114 ASSERT(previous_index <= subject->length()); | 114 ASSERT(previous_index <= subject->length()); |
115 | 115 |
116 // No allocations before calling the regexp, but we can't use | 116 // No allocations before calling the regexp, but we can't use |
117 // AssertNoAllocation, since regexps might be preempted, and another thread | 117 // AssertNoAllocation, since regexps might be preempted, and another thread |
118 // might do allocation anyway. | 118 // might do allocation anyway. |
119 | 119 |
120 String* subject_ptr = *subject; | 120 String* subject_ptr = *subject; |
121 // Character offsets into string. | 121 // Character offsets into string. |
122 int start_offset = previous_index; | 122 int start_offset = previous_index; |
123 int end_offset = subject_ptr->length(); | 123 int char_length = subject_ptr->length() - start_offset; |
| 124 int slice_offset = 0; |
124 | 125 |
125 // The string has been flattened, so it it is a cons string it contains the | 126 // The string has been flattened, so if it is a cons string it contains the |
126 // full string in the first part. | 127 // full string in the first part. |
127 if (StringShape(subject_ptr).IsCons()) { | 128 if (StringShape(subject_ptr).IsCons()) { |
128 ASSERT_EQ(0, ConsString::cast(subject_ptr)->second()->length()); | 129 ASSERT_EQ(0, ConsString::cast(subject_ptr)->second()->length()); |
129 subject_ptr = ConsString::cast(subject_ptr)->first(); | 130 subject_ptr = ConsString::cast(subject_ptr)->first(); |
| 131 } else if (StringShape(subject_ptr).IsSliced()) { |
| 132 SlicedString* slice = SlicedString::cast(subject_ptr); |
| 133 subject_ptr = slice->parent(); |
| 134 slice_offset = slice->offset(); |
130 } | 135 } |
131 // Ensure that an underlying string has the same ascii-ness. | 136 // Ensure that an underlying string has the same ascii-ness. |
132 bool is_ascii = subject_ptr->IsAsciiRepresentation(); | 137 bool is_ascii = subject_ptr->IsAsciiRepresentation(); |
133 ASSERT(subject_ptr->IsExternalString() || subject_ptr->IsSeqString()); | 138 ASSERT(subject_ptr->IsExternalString() || subject_ptr->IsSeqString()); |
134 // String is now either Sequential or External | 139 // String is now either Sequential or External |
135 int char_size_shift = is_ascii ? 0 : 1; | 140 int char_size_shift = is_ascii ? 0 : 1; |
136 int char_length = end_offset - start_offset; | |
137 | 141 |
138 const byte* input_start = | 142 const byte* input_start = |
139 StringCharacterPosition(subject_ptr, start_offset); | 143 StringCharacterPosition(subject_ptr, start_offset + slice_offset); |
140 int byte_length = char_length << char_size_shift; | 144 int byte_length = char_length << char_size_shift; |
141 const byte* input_end = input_start + byte_length; | 145 const byte* input_end = input_start + byte_length; |
142 Result res = Execute(*regexp_code, | 146 Result res = Execute(*regexp_code, |
143 subject_ptr, | 147 *subject, |
144 start_offset, | 148 start_offset, |
145 input_start, | 149 input_start, |
146 input_end, | 150 input_end, |
147 offsets_vector, | 151 offsets_vector, |
148 isolate); | 152 isolate); |
149 return res; | 153 return res; |
150 } | 154 } |
151 | 155 |
152 | 156 |
153 NativeRegExpMacroAssembler::Result NativeRegExpMacroAssembler::Execute( | 157 NativeRegExpMacroAssembler::Result NativeRegExpMacroAssembler::Execute( |
154 Code* code, | 158 Code* code, |
155 String* input, | 159 String* input, // This needs to be the unpacked (sliced, cons) string. |
156 int start_offset, | 160 int start_offset, |
157 const byte* input_start, | 161 const byte* input_start, |
158 const byte* input_end, | 162 const byte* input_end, |
159 int* output, | 163 int* output, |
160 Isolate* isolate) { | 164 Isolate* isolate) { |
161 ASSERT(isolate == Isolate::Current()); | 165 ASSERT(isolate == Isolate::Current()); |
162 // Ensure that the minimum stack has been allocated. | 166 // Ensure that the minimum stack has been allocated. |
163 RegExpStackScope stack_scope(isolate); | 167 RegExpStackScope stack_scope(isolate); |
164 Address stack_base = stack_scope.stack()->stack_base(); | 168 Address stack_base = stack_scope.stack()->stack_base(); |
165 | 169 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 return NULL; | 262 return NULL; |
259 } | 263 } |
260 *stack_base = new_stack_base; | 264 *stack_base = new_stack_base; |
261 intptr_t stack_content_size = old_stack_base - stack_pointer; | 265 intptr_t stack_content_size = old_stack_base - stack_pointer; |
262 return new_stack_base - stack_content_size; | 266 return new_stack_base - stack_content_size; |
263 } | 267 } |
264 | 268 |
265 #endif // V8_INTERPRETED_REGEXP | 269 #endif // V8_INTERPRETED_REGEXP |
266 | 270 |
267 } } // namespace v8::internal | 271 } } // namespace v8::internal |
OLD | NEW |