| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 bool read_all_at_once) | 102 bool read_all_at_once) |
| 103 : current_(0), | 103 : current_(0), |
| 104 fetched_(0), | 104 fetched_(0), |
| 105 read_all_at_once_(read_all_at_once), | 105 read_all_at_once_(read_all_at_once), |
| 106 source_(0), | 106 source_(0), |
| 107 length_(0) { | 107 length_(0) { |
| 108 file_ = fopen(fname, "rb"); | 108 file_ = fopen(fname, "rb"); |
| 109 scanner_ = new PushScanner(this); | 109 scanner_ = new PushScanner(this); |
| 110 if (read_all_at_once_) { | 110 if (read_all_at_once_) { |
| 111 source_ = ReadFile(fname, NULL, &length_); | 111 source_ = ReadFile(fname, NULL, &length_); |
| 112 token_.resize(1500); |
| 113 beg_.resize(1500); |
| 114 end_.resize(1500); |
| 115 } else { |
| 116 token_.resize(BUFFER_SIZE); |
| 117 beg_.resize(BUFFER_SIZE); |
| 118 end_.resize(BUFFER_SIZE); |
| 112 } | 119 } |
| 113 } | 120 } |
| 114 | 121 |
| 115 | 122 |
| 116 ExperimentalScanner::~ExperimentalScanner() { | 123 ExperimentalScanner::~ExperimentalScanner() { |
| 117 fclose(file_); | 124 fclose(file_); |
| 118 delete[] source_; | 125 delete[] source_; |
| 119 } | 126 } |
| 120 | 127 |
| 121 | 128 |
| 122 void ExperimentalScanner::FillTokens() { | 129 void ExperimentalScanner::FillTokens() { |
| 123 current_ = 0; | 130 current_ = 0; |
| 124 fetched_ = 0; | 131 fetched_ = 0; |
| 125 if (read_all_at_once_) { | 132 if (read_all_at_once_) { |
| 126 scanner_->push(source_, length_ + 1); | 133 scanner_->push(source_, length_ + 1); |
| 127 } else { | 134 } else { |
| 128 uint8_t chars[BUFFER_SIZE]; | 135 uint8_t chars[BUFFER_SIZE]; |
| 129 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_)); | 136 int n = static_cast<int>(fread(&chars, 1, BUFFER_SIZE, file_)); |
| 130 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0; | 137 for (int i = n; i < BUFFER_SIZE; i++) chars[i] = 0; |
| 131 scanner_->push(chars, BUFFER_SIZE); | 138 scanner_->push(chars, BUFFER_SIZE); |
| 132 } | 139 } |
| 133 } | 140 } |
| 134 | 141 |
| 135 | 142 |
| 136 Token::Value ExperimentalScanner::Next(int* beg_pos, int* end_pos) { | 143 Token::Value ExperimentalScanner::Next(int* beg_pos, int* end_pos) { |
| 137 while (current_ == fetched_) { | 144 while (current_ == fetched_) |
| 138 FillTokens(); | 145 FillTokens(); |
| 139 } | |
| 140 *beg_pos = beg_[current_]; | 146 *beg_pos = beg_[current_]; |
| 141 *end_pos = end_[current_]; | 147 *end_pos = end_[current_]; |
| 142 Token::Value res = token_[current_]; | 148 Token::Value res = token_[current_]; |
| 143 if (token_[current_] != Token::Token::EOS && | 149 if (res != Token::Token::EOS) |
| 144 token_[current_] != Token::ILLEGAL) { | |
| 145 current_++; | 150 current_++; |
| 146 } | |
| 147 return res; | 151 return res; |
| 148 } | 152 } |
| 149 | 153 |
| 150 | 154 |
| 151 void ExperimentalScanner::Record(Token::Value token, int beg, int end) { | 155 void ExperimentalScanner::Record(Token::Value token, int beg, int end) { |
| 152 if (token == Token::EOS) end--; | 156 if (token == Token::EOS) end--; |
| 153 if (fetched_ >= token_.size()) { | 157 if (fetched_ >= token_.size()) { |
| 154 token_.push_back(token); | 158 token_.resize(token_.size() * 2); |
| 155 beg_.push_back(beg); | 159 beg_.resize(beg_.size() * 2); |
| 156 end_.push_back(end); | 160 end_.resize(end_.size() * 2); |
| 157 } else { | |
| 158 token_[fetched_] = token; | |
| 159 beg_[fetched_] = beg; | |
| 160 end_[fetched_] = end; | |
| 161 } | 161 } |
| 162 token_[fetched_] = token; |
| 163 beg_[fetched_] = beg; |
| 164 end_[fetched_] = end; |
| 162 fetched_++; | 165 fetched_++; |
| 163 } | 166 } |
| 164 | 167 |
| 165 | 168 |
| 166 int main(int argc, char* argv[]) { | 169 int main(int argc, char* argv[]) { |
| 167 v8::V8::InitializeICU(); | 170 v8::V8::InitializeICU(); |
| 168 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); | 171 v8::V8::SetFlagsFromCommandLine(&argc, argv, true); |
| 169 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 172 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 170 { | 173 { |
| 171 v8::HandleScope handle_scope(isolate); | 174 v8::HandleScope handle_scope(isolate); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 printf("MISMATCH:\n"); | 222 printf("MISMATCH:\n"); |
| 220 printf("Expected: %s at (%d, %d)\n", | 223 printf("Expected: %s at (%d, %d)\n", |
| 221 Token::Name(baseline_tokens[i]), | 224 Token::Name(baseline_tokens[i]), |
| 222 baseline_beg[i], baseline_end[i]); | 225 baseline_beg[i], baseline_end[i]); |
| 223 printf("Actual: %s at (%d, %d)\n", | 226 printf("Actual: %s at (%d, %d)\n", |
| 224 Token::Name(experimental_tokens[i]), | 227 Token::Name(experimental_tokens[i]), |
| 225 experimental_beg[i], experimental_end[i]); | 228 experimental_beg[i], experimental_end[i]); |
| 226 return 1; | 229 return 1; |
| 227 } | 230 } |
| 228 } | 231 } |
| 232 printf("No of tokens: %d\n", experimental_tokens.size()); |
| 229 printf("Baseline: %f ms\nExperimental %f ms\n", | 233 printf("Baseline: %f ms\nExperimental %f ms\n", |
| 230 baseline_time.InMillisecondsF(), | 234 baseline_time.InMillisecondsF(), |
| 231 experimental_time.InMillisecondsF()); | 235 experimental_time.InMillisecondsF()); |
| 232 } | 236 } |
| 233 } | 237 } |
| 234 v8::V8::Dispose(); | 238 v8::V8::Dispose(); |
| 235 return 0; | 239 return 0; |
| 236 } | 240 } |
| OLD | NEW |