| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 ASSERT(from >= 0); | 1139 ASSERT(from >= 0); |
| 1140 int length = to - from; | 1140 int length = to - from; |
| 1141 ASSERT(length >= 0); | 1141 ASSERT(length >= 0); |
| 1142 if (length > 0) { | 1142 if (length > 0) { |
| 1143 // Can we encode the slice in 11 bits for length and 19 bits for | 1143 // Can we encode the slice in 11 bits for length and 19 bits for |
| 1144 // start position - as used by StringBuilderConcatHelper? | 1144 // start position - as used by StringBuilderConcatHelper? |
| 1145 if (StringBuilderSubstringLength::is_valid(length) && | 1145 if (StringBuilderSubstringLength::is_valid(length) && |
| 1146 StringBuilderSubstringPosition::is_valid(from)) { | 1146 StringBuilderSubstringPosition::is_valid(from)) { |
| 1147 int encoded_slice = StringBuilderSubstringLength::encode(length) | | 1147 int encoded_slice = StringBuilderSubstringLength::encode(length) | |
| 1148 StringBuilderSubstringPosition::encode(from); | 1148 StringBuilderSubstringPosition::encode(from); |
| 1149 AddElement(Smi::FromInt(encoded_slice)); | 1149 AddElement(Handle<Object>(Smi::FromInt(encoded_slice))); |
| 1150 } else { | 1150 } else { |
| 1151 Handle<String> slice = Factory::NewStringSlice(subject_, from, to); | 1151 Handle<String> slice = Factory::NewStringSlice(subject_, from, to); |
| 1152 AddElement(*slice); | 1152 AddElement(slice); |
| 1153 } | 1153 } |
| 1154 IncrementCharacterCount(length); | 1154 IncrementCharacterCount(length); |
| 1155 } | 1155 } |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 | 1158 |
| 1159 void AddString(Handle<String> string) { | 1159 void AddString(Handle<String> string) { |
| 1160 StringShape shape(*string); | 1160 StringShape shape(*string); |
| 1161 int length = string->length(shape); | 1161 int length = string->length(shape); |
| 1162 if (length > 0) { | 1162 if (length > 0) { |
| 1163 AddElement(*string); | 1163 AddElement(string); |
| 1164 if (!shape.IsAsciiRepresentation()) { | 1164 if (!shape.IsAsciiRepresentation()) { |
| 1165 is_ascii_ = false; | 1165 is_ascii_ = false; |
| 1166 } | 1166 } |
| 1167 IncrementCharacterCount(length); | 1167 IncrementCharacterCount(length); |
| 1168 } | 1168 } |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 | 1171 |
| 1172 Handle<String> ToString() { | 1172 Handle<String> ToString() { |
| 1173 if (part_count_ == 0) { | 1173 if (part_count_ == 0) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 Handle<String> NewRawAsciiString(int size) { | 1213 Handle<String> NewRawAsciiString(int size) { |
| 1214 CALL_HEAP_FUNCTION(Heap::AllocateRawAsciiString(size), String); | 1214 CALL_HEAP_FUNCTION(Heap::AllocateRawAsciiString(size), String); |
| 1215 } | 1215 } |
| 1216 | 1216 |
| 1217 | 1217 |
| 1218 Handle<String> NewRawTwoByteString(int size) { | 1218 Handle<String> NewRawTwoByteString(int size) { |
| 1219 CALL_HEAP_FUNCTION(Heap::AllocateRawTwoByteString(size), String); | 1219 CALL_HEAP_FUNCTION(Heap::AllocateRawTwoByteString(size), String); |
| 1220 } | 1220 } |
| 1221 | 1221 |
| 1222 | 1222 |
| 1223 void AddElement(Object* element) { | 1223 void AddElement(Handle<Object> element) { |
| 1224 ASSERT(element->IsSmi() || element->IsString()); | 1224 ASSERT(element->IsSmi() || element->IsString()); |
| 1225 // Extend parts_ array if necessary. | 1225 // Extend parts_ array if necessary. |
| 1226 if (parts_->length() == part_count_) { | 1226 if (parts_->length() == part_count_) { |
| 1227 Handle<FixedArray> extended_array = | 1227 Handle<FixedArray> extended_array = |
| 1228 Factory::NewFixedArray(part_count_ * 2); | 1228 Factory::NewFixedArray(part_count_ * 2); |
| 1229 parts_->CopyTo(0, *extended_array, 0, part_count_); | 1229 parts_->CopyTo(0, *extended_array, 0, part_count_); |
| 1230 parts_ = extended_array; | 1230 parts_ = extended_array; |
| 1231 } | 1231 } |
| 1232 parts_->set(part_count_, element); | 1232 parts_->set(part_count_, *element); |
| 1233 part_count_++; | 1233 part_count_++; |
| 1234 } | 1234 } |
| 1235 | 1235 |
| 1236 Handle<String> subject_; | 1236 Handle<String> subject_; |
| 1237 Handle<FixedArray> parts_; | 1237 Handle<FixedArray> parts_; |
| 1238 int part_count_; | 1238 int part_count_; |
| 1239 int character_count_; | 1239 int character_count_; |
| 1240 bool is_ascii_; | 1240 bool is_ascii_; |
| 1241 }; | 1241 }; |
| 1242 | 1242 |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1544 // conservatively. | 1544 // conservatively. |
| 1545 int expected_parts = | 1545 int expected_parts = |
| 1546 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; | 1546 (compiled_replacement.parts() + 1) * (is_global ? 4 : 1) + 1; |
| 1547 ReplacementStringBuilder builder(subject_handle, expected_parts); | 1547 ReplacementStringBuilder builder(subject_handle, expected_parts); |
| 1548 | 1548 |
| 1549 // Index of end of last match. | 1549 // Index of end of last match. |
| 1550 int prev = 0; | 1550 int prev = 0; |
| 1551 | 1551 |
| 1552 do { | 1552 do { |
| 1553 ASSERT(last_match_info_handle->HasFastElements()); | 1553 ASSERT(last_match_info_handle->HasFastElements()); |
| 1554 FixedArray* match_info_array = last_match_info_handle->elements(); | 1554 int start, end; |
| 1555 { |
| 1556 AssertNoAllocation a; |
| 1557 FixedArray* match_info_array = last_match_info_handle->elements(); |
| 1555 | 1558 |
| 1556 ASSERT_EQ(capture_count * 2 + 2, | 1559 ASSERT_EQ(capture_count * 2 + 2, |
| 1557 RegExpImpl::GetLastCaptureCount(match_info_array)); | 1560 RegExpImpl::GetLastCaptureCount(match_info_array)); |
| 1558 int start = RegExpImpl::GetCapture(match_info_array, 0); | 1561 start = RegExpImpl::GetCapture(match_info_array, 0); |
| 1559 int end = RegExpImpl::GetCapture(match_info_array, 1); | 1562 end = RegExpImpl::GetCapture(match_info_array, 1); |
| 1563 } |
| 1560 | 1564 |
| 1561 if (prev < start) { | 1565 if (prev < start) { |
| 1562 builder.AddSubjectSlice(prev, start); | 1566 builder.AddSubjectSlice(prev, start); |
| 1563 } | 1567 } |
| 1564 compiled_replacement.Apply(&builder, | 1568 compiled_replacement.Apply(&builder, |
| 1565 start, | 1569 start, |
| 1566 end, | 1570 end, |
| 1567 last_match_info_handle); | 1571 last_match_info_handle); |
| 1568 prev = end; | 1572 prev = end; |
| 1569 | 1573 |
| (...skipping 5082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6652 } else { | 6656 } else { |
| 6653 // Handle last resort GC and make sure to allow future allocations | 6657 // Handle last resort GC and make sure to allow future allocations |
| 6654 // to grow the heap without causing GCs (if possible). | 6658 // to grow the heap without causing GCs (if possible). |
| 6655 Counters::gc_last_resort_from_js.Increment(); | 6659 Counters::gc_last_resort_from_js.Increment(); |
| 6656 Heap::CollectAllGarbage(); | 6660 Heap::CollectAllGarbage(); |
| 6657 } | 6661 } |
| 6658 } | 6662 } |
| 6659 | 6663 |
| 6660 | 6664 |
| 6661 } } // namespace v8::internal | 6665 } } // namespace v8::internal |
| OLD | NEW |