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

Side by Side Diff: src/jsregexp.cc

Issue 12184015: Inline some regexp code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 10 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
« no previous file with comments | « src/jsregexp.h ('k') | src/jsregexp-inl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h" 28 #include "v8.h"
29 29
30 #include "ast.h" 30 #include "ast.h"
31 #include "compiler.h" 31 #include "compiler.h"
32 #include "execution.h" 32 #include "execution.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "jsregexp.h" 34 #include "jsregexp.h"
35 #include "jsregexp-inl.h"
35 #include "platform.h" 36 #include "platform.h"
36 #include "string-search.h" 37 #include "string-search.h"
37 #include "runtime.h" 38 #include "runtime.h"
38 #include "compilation-cache.h" 39 #include "compilation-cache.h"
39 #include "string-stream.h" 40 #include "string-stream.h"
40 #include "parser.h" 41 #include "parser.h"
41 #include "regexp-macro-assembler.h" 42 #include "regexp-macro-assembler.h"
42 #include "regexp-macro-assembler-tracer.h" 43 #include "regexp-macro-assembler-tracer.h"
43 #include "regexp-macro-assembler-irregexp.h" 44 #include "regexp-macro-assembler-irregexp.h"
44 #include "regexp-stack.h" 45 #include "regexp-stack.h"
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 num_matches_ = max_matches_; 754 num_matches_ = max_matches_;
754 ASSERT(registers_per_match_ >= 2); // Each match has at least one capture. 755 ASSERT(registers_per_match_ >= 2); // Each match has at least one capture.
755 ASSERT_GE(register_array_size_, registers_per_match_); 756 ASSERT_GE(register_array_size_, registers_per_match_);
756 int32_t* last_match = 757 int32_t* last_match =
757 &register_array_[current_match_index_ * registers_per_match_]; 758 &register_array_[current_match_index_ * registers_per_match_];
758 last_match[0] = -1; 759 last_match[0] = -1;
759 last_match[1] = 0; 760 last_match[1] = 0;
760 } 761 }
761 762
762 763
763 RegExpImpl::GlobalCache::~GlobalCache() {
764 // Deallocate the register array if we allocated it in the constructor
765 // (as opposed to using the existing jsregexp_static_offsets_vector).
766 if (register_array_size_ > Isolate::kJSRegexpStaticOffsetsVectorSize) {
767 DeleteArray(register_array_);
768 }
769 }
770
771
772 int32_t* RegExpImpl::GlobalCache::FetchNext() {
773 current_match_index_++;
774 if (current_match_index_ >= num_matches_) {
775 // Current batch of results exhausted.
776 // Fail if last batch was not even fully filled.
777 if (num_matches_ < max_matches_) {
778 num_matches_ = 0; // Signal failed match.
779 return NULL;
780 }
781
782 int32_t* last_match =
783 &register_array_[(current_match_index_ - 1) * registers_per_match_];
784 int last_end_index = last_match[1];
785
786 if (regexp_->TypeTag() == JSRegExp::ATOM) {
787 num_matches_ = RegExpImpl::AtomExecRaw(regexp_,
788 subject_,
789 last_end_index,
790 register_array_,
791 register_array_size_);
792 } else {
793 int last_start_index = last_match[0];
794 if (last_start_index == last_end_index) last_end_index++;
795 if (last_end_index > subject_->length()) {
796 num_matches_ = 0; // Signal failed match.
797 return NULL;
798 }
799 num_matches_ = RegExpImpl::IrregexpExecRaw(regexp_,
800 subject_,
801 last_end_index,
802 register_array_,
803 register_array_size_);
804 }
805
806 if (num_matches_ <= 0) return NULL;
807 current_match_index_ = 0;
808 return register_array_;
809 } else {
810 return &register_array_[current_match_index_ * registers_per_match_];
811 }
812 }
813
814
815 int32_t* RegExpImpl::GlobalCache::LastSuccessfulMatch() {
816 int index = current_match_index_ * registers_per_match_;
817 if (num_matches_ == 0) {
818 // After a failed match we shift back by one result.
819 index -= registers_per_match_;
820 }
821 return &register_array_[index];
822 }
823
824
825 // ------------------------------------------------------------------- 764 // -------------------------------------------------------------------
826 // Implementation of the Irregexp regular expression engine. 765 // Implementation of the Irregexp regular expression engine.
827 // 766 //
828 // The Irregexp regular expression engine is intended to be a complete 767 // The Irregexp regular expression engine is intended to be a complete
829 // implementation of ECMAScript regular expressions. It generates either 768 // implementation of ECMAScript regular expressions. It generates either
830 // bytecodes or native code. 769 // bytecodes or native code.
831 770
832 // The Irregexp regexp engine is structured in three steps. 771 // The Irregexp regexp engine is structured in three steps.
833 // 1) The parser generates an abstract syntax tree. See ast.cc. 772 // 1) The parser generates an abstract syntax tree. See ast.cc.
834 // 2) From the AST a node network is created. The nodes are all 773 // 2) From the AST a node network is created. The nodes are all
(...skipping 5375 matching lines...) Expand 10 before | Expand all | Expand 10 after
6210 } 6149 }
6211 6150
6212 return compiler.Assemble(&macro_assembler, 6151 return compiler.Assemble(&macro_assembler,
6213 node, 6152 node,
6214 data->capture_count, 6153 data->capture_count,
6215 pattern); 6154 pattern);
6216 } 6155 }
6217 6156
6218 6157
6219 }} // namespace v8::internal 6158 }} // namespace v8::internal
OLDNEW
« no previous file with comments | « src/jsregexp.h ('k') | src/jsregexp-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698