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

Side by Side Diff: src/jsregexp.cc

Issue 3844006: Limit end-anchored regexps to testing end of string where possible. (Closed)
Patch Set: Created 10 years, 2 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
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 5162 matching lines...) Expand 10 before | Expand all | Expand 10 after
5173 if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) { 5173 if ((data->capture_count + 1) * 2 - 1 > RegExpMacroAssembler::kMaxRegister) {
5174 return IrregexpRegExpTooBig(); 5174 return IrregexpRegExpTooBig();
5175 } 5175 }
5176 RegExpCompiler compiler(data->capture_count, ignore_case, is_ascii); 5176 RegExpCompiler compiler(data->capture_count, ignore_case, is_ascii);
5177 // Wrap the body of the regexp in capture #0. 5177 // Wrap the body of the regexp in capture #0.
5178 RegExpNode* captured_body = RegExpCapture::ToNode(data->tree, 5178 RegExpNode* captured_body = RegExpCapture::ToNode(data->tree,
5179 0, 5179 0,
5180 &compiler, 5180 &compiler,
5181 compiler.accept()); 5181 compiler.accept());
5182 RegExpNode* node = captured_body; 5182 RegExpNode* node = captured_body;
5183 if (!data->tree->IsAnchored()) { 5183 bool is_end_anchored = data->tree->IsAnchoredAtEnd();
5184 bool is_start_anchored = data->tree->IsAnchoredAtStart();
5185 int max_length = data->tree->max_match();
5186 if (!is_start_anchored) {
5184 // Add a .*? at the beginning, outside the body capture, unless 5187 // Add a .*? at the beginning, outside the body capture, unless
5185 // this expression is anchored at the beginning. 5188 // this expression is anchored at the beginning.
5186 RegExpNode* loop_node = 5189 RegExpNode* loop_node =
5187 RegExpQuantifier::ToNode(0, 5190 RegExpQuantifier::ToNode(0,
5188 RegExpTree::kInfinity, 5191 RegExpTree::kInfinity,
5189 false, 5192 false,
5190 new RegExpCharacterClass('*'), 5193 new RegExpCharacterClass('*'),
5191 &compiler, 5194 &compiler,
5192 captured_body, 5195 captured_body,
5193 data->contains_anchor); 5196 data->contains_anchor);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
5229 #elif V8_TARGET_ARCH_ARM 5232 #elif V8_TARGET_ARCH_ARM
5230 RegExpMacroAssemblerARM macro_assembler(mode, (data->capture_count + 1) * 2); 5233 RegExpMacroAssemblerARM macro_assembler(mode, (data->capture_count + 1) * 2);
5231 #endif 5234 #endif
5232 5235
5233 #else // V8_INTERPRETED_REGEXP 5236 #else // V8_INTERPRETED_REGEXP
5234 // Interpreted regexp implementation. 5237 // Interpreted regexp implementation.
5235 EmbeddedVector<byte, 1024> codes; 5238 EmbeddedVector<byte, 1024> codes;
5236 RegExpMacroAssemblerIrregexp macro_assembler(codes); 5239 RegExpMacroAssemblerIrregexp macro_assembler(codes);
5237 #endif // V8_INTERPRETED_REGEXP 5240 #endif // V8_INTERPRETED_REGEXP
5238 5241
5242 // Inserted here, instead of in Assembler, because it depends on information
5243 // in the AST that isn't replicated in the Node structure.
5244 static const int kMaxBacksearchLimit = 1024;
5245 if (is_end_anchored &&
5246 !is_start_anchored &&
5247 max_length < kMaxBacksearchLimit) {
5248 macro_assembler.SetCurrentPositionFromEnd(max_length);
5249 }
5250
5239 return compiler.Assemble(&macro_assembler, 5251 return compiler.Assemble(&macro_assembler,
5240 node, 5252 node,
5241 data->capture_count, 5253 data->capture_count,
5242 pattern); 5254 pattern);
5243 } 5255 }
5244 5256
5245 5257
5246 int OffsetsVector::static_offsets_vector_[ 5258 int OffsetsVector::static_offsets_vector_[
5247 OffsetsVector::kStaticOffsetsVectorSize]; 5259 OffsetsVector::kStaticOffsetsVectorSize];
5248 5260
5249 }} // namespace v8::internal 5261 }} // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698