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

Side by Side Diff: src/runtime.cc

Issue 1795005: Fix search-for-string and replace global to avoid hangs... (Closed) Base URL: http://v8.googlecode.com/svn/branches/2.1/
Patch Set: Created 10 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 3051 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 FixedArrayBuilder* builder, 3062 FixedArrayBuilder* builder,
3063 int* match_pos) { 3063 int* match_pos) {
3064 int pos = *match_pos; 3064 int pos = *match_pos;
3065 int subject_length = subject.length(); 3065 int subject_length = subject.length();
3066 int pattern_length = pattern_string.length(); 3066 int pattern_length = pattern_string.length();
3067 int max_search_start = subject_length - pattern_length; 3067 int max_search_start = subject_length - pattern_length;
3068 bool is_ascii = (sizeof(schar) == 1); 3068 bool is_ascii = (sizeof(schar) == 1);
3069 StringSearchStrategy strategy = 3069 StringSearchStrategy strategy =
3070 InitializeStringSearch(pattern_string, is_ascii); 3070 InitializeStringSearch(pattern_string, is_ascii);
3071 switch (strategy) { 3071 switch (strategy) {
3072 case SEARCH_FAIL: return false; 3072 case SEARCH_FAIL: break;
3073 case SEARCH_SHORT: 3073 case SEARCH_SHORT:
3074 while (pos <= max_search_start) { 3074 while (pos <= max_search_start) {
3075 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) { 3075 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) {
3076 *match_pos = pos; 3076 *match_pos = pos;
3077 return false; 3077 return false;
3078 } 3078 }
3079 // Position of end of previous match. 3079 // Position of end of previous match.
3080 int match_end = pos + pattern_length; 3080 int match_end = pos + pattern_length;
3081 int new_pos = SimpleIndexOf(subject, pattern_string, match_end); 3081 int new_pos = SimpleIndexOf(subject, pattern_string, match_end);
3082 if (new_pos >= 0) { 3082 if (new_pos >= 0) {
3083 // A match. 3083 // A match.
3084 if (new_pos > match_end) { 3084 if (new_pos > match_end) {
3085 ReplacementStringBuilder::AddSubjectSlice(builder, 3085 ReplacementStringBuilder::AddSubjectSlice(builder,
3086 match_end, 3086 match_end,
3087 new_pos); 3087 new_pos);
3088 } 3088 }
3089 pos = new_pos; 3089 pos = new_pos;
3090 builder->Add(pattern); 3090 builder->Add(pattern);
3091 } else { 3091 } else {
3092 break; 3092 break;
3093 } 3093 }
3094 } 3094 }
3095 break; 3095 break;
3096 case SEARCH_LONG: 3096 case SEARCH_LONG:
3097 while (pos <= max_search_start) { 3097 while (pos <= max_search_start) {
3098 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) { 3098 if (!builder->HasCapacity(kMaxBuilderEntriesPerRegExpMatch)) {
3099 *match_pos = pos; 3099 *match_pos = pos;
3100 return false; 3100 return false;
3101 } 3101 }
3102 int new_pos = ComplexIndexOf(subject, 3102 int match_end = pos + pattern_length;
3103 pattern_string, 3103 int new_pos = ComplexIndexOf(subject, pattern_string, match_end);
3104 pos + pattern_length);
3105 if (new_pos >= 0) { 3104 if (new_pos >= 0) {
3106 // A match has been found. 3105 // A match has been found.
3107 if (new_pos > pos) { 3106 if (new_pos > match_end) {
3108 ReplacementStringBuilder::AddSubjectSlice(builder, pos, new_pos); 3107 ReplacementStringBuilder::AddSubjectSlice(builder,
3108 match_end,
3109 new_pos);
3109 } 3110 }
3110 pos = new_pos; 3111 pos = new_pos;
3111 builder->Add(pattern); 3112 builder->Add(pattern);
3112 } else { 3113 } else {
3113 break; 3114 break;
3114 } 3115 }
3115 } 3116 }
3116 break; 3117 break;
3117 } 3118 }
3118 if (pos < max_search_start) { 3119 if (pos < max_search_start) {
(...skipping 6869 matching lines...) Expand 10 before | Expand all | Expand 10 after
9988 } else { 9989 } else {
9989 // Handle last resort GC and make sure to allow future allocations 9990 // Handle last resort GC and make sure to allow future allocations
9990 // to grow the heap without causing GCs (if possible). 9991 // to grow the heap without causing GCs (if possible).
9991 Counters::gc_last_resort_from_js.Increment(); 9992 Counters::gc_last_resort_from_js.Increment();
9992 Heap::CollectAllGarbage(false); 9993 Heap::CollectAllGarbage(false);
9993 } 9994 }
9994 } 9995 }
9995 9996
9996 9997
9997 } } // namespace v8::internal 9998 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/search-string-multiple.js » ('j') | test/mjsunit/search-string-multiple.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698