OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3940 match_end = current_match[1]; | 3940 match_end = current_match[1]; |
3941 | 3941 |
3942 { | 3942 { |
3943 // Avoid accumulating new handles inside loop. | 3943 // Avoid accumulating new handles inside loop. |
3944 HandleScope temp_scope(isolate); | 3944 HandleScope temp_scope(isolate); |
3945 // Arguments array to replace function is match, captures, index and | 3945 // Arguments array to replace function is match, captures, index and |
3946 // subject, i.e., 3 + capture count in total. | 3946 // subject, i.e., 3 + capture count in total. |
3947 Handle<FixedArray> elements = | 3947 Handle<FixedArray> elements = |
3948 isolate->factory()->NewFixedArray(3 + capture_count); | 3948 isolate->factory()->NewFixedArray(3 + capture_count); |
3949 Handle<String> match; | 3949 Handle<String> match; |
3950 if (!first) { | 3950 if (!first) { |
Lasse Reichstein Nielsen
2012/05/29 09:06:52
"first" is actually badly named. It should be "atS
| |
3951 match = isolate->factory()->NewProperSubString(subject, | 3951 match = isolate->factory()->NewProperSubString(subject, |
3952 match_start, | 3952 match_start, |
3953 match_end); | 3953 match_end); |
3954 } else { | 3954 } else { |
3955 match = isolate->factory()->NewSubString(subject, | 3955 match = isolate->factory()->NewSubString(subject, |
3956 match_start, | 3956 match_start, |
3957 match_end); | 3957 match_end); |
3958 first = false; | |
3959 } | 3958 } |
3960 elements->set(0, *match); | 3959 elements->set(0, *match); |
3961 for (int i = 1; i <= capture_count; i++) { | 3960 for (int i = 1; i <= capture_count; i++) { |
3962 int start = current_match[i * 2]; | 3961 int start = current_match[i * 2]; |
3963 if (start >= 0) { | 3962 if (start >= 0) { |
3964 int end = current_match[i * 2 + 1]; | 3963 int end = current_match[i * 2 + 1]; |
3965 ASSERT(start <= end); | 3964 ASSERT(start <= end); |
3966 Handle<String> substring = | 3965 Handle<String> substring; |
3967 isolate->factory()->NewProperSubString(subject, start, end); | 3966 if (!first) { |
Lasse Reichstein Nielsen
2012/05/29 09:06:52
Perhaps drop "first" and just check if start > 0 h
| |
3967 substring = | |
3968 isolate->factory()->NewProperSubString(subject, start, end); | |
3969 } else { | |
3970 substring = | |
3971 isolate->factory()->NewSubString(subject, start, end); | |
3972 } | |
3968 elements->set(i, *substring); | 3973 elements->set(i, *substring); |
3969 } else { | 3974 } else { |
3970 ASSERT(current_match[i * 2 + 1] < 0); | 3975 ASSERT(current_match[i * 2 + 1] < 0); |
3971 elements->set(i, isolate->heap()->undefined_value()); | 3976 elements->set(i, isolate->heap()->undefined_value()); |
3972 } | 3977 } |
3973 } | 3978 } |
3974 elements->set(capture_count + 1, Smi::FromInt(match_start)); | 3979 elements->set(capture_count + 1, Smi::FromInt(match_start)); |
3975 elements->set(capture_count + 2, *subject); | 3980 elements->set(capture_count + 2, *subject); |
3976 builder->Add(*isolate->factory()->NewJSArrayWithElements(elements)); | 3981 builder->Add(*isolate->factory()->NewJSArrayWithElements(elements)); |
3977 } | 3982 } |
3983 first = false; | |
3978 } | 3984 } |
3979 | 3985 |
3980 // If we did not get the maximum number of matches, we can stop here | 3986 // If we did not get the maximum number of matches, we can stop here |
3981 // since there are no matches left. | 3987 // since there are no matches left. |
3982 if (num_matches < max_matches) break; | 3988 if (num_matches < max_matches) break; |
3983 | 3989 |
3984 if (match_end > match_start) { | 3990 if (match_end > match_start) { |
3985 pos = match_end; | 3991 pos = match_end; |
3986 } else { | 3992 } else { |
3987 pos = match_end + 1; | 3993 pos = match_end + 1; |
(...skipping 9551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13539 // Handle last resort GC and make sure to allow future allocations | 13545 // Handle last resort GC and make sure to allow future allocations |
13540 // to grow the heap without causing GCs (if possible). | 13546 // to grow the heap without causing GCs (if possible). |
13541 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13547 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13542 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13548 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13543 "Runtime::PerformGC"); | 13549 "Runtime::PerformGC"); |
13544 } | 13550 } |
13545 } | 13551 } |
13546 | 13552 |
13547 | 13553 |
13548 } } // namespace v8::internal | 13554 } } // namespace v8::internal |
OLD | NEW |