OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Features shared by parsing and pre-parsing scanners. | 5 // Features shared by parsing and pre-parsing scanners. |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 Advance(); | 323 Advance(); |
324 LiteralBuffer name; | 324 LiteralBuffer name; |
325 while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_) && | 325 while (c0_ >= 0 && !unicode_cache_->IsWhiteSpaceOrLineTerminator(c0_) && |
326 c0_ != '=') { | 326 c0_ != '=') { |
327 name.AddChar(c0_); | 327 name.AddChar(c0_); |
328 Advance(); | 328 Advance(); |
329 } | 329 } |
330 if (!name.is_one_byte()) return; | 330 if (!name.is_one_byte()) return; |
331 Vector<const uint8_t> name_literal = name.one_byte_literal(); | 331 Vector<const uint8_t> name_literal = name.one_byte_literal(); |
332 LiteralBuffer* value; | 332 LiteralBuffer* value; |
333 if (name_literal == STATIC_ASCII_VECTOR("sourceURL")) { | 333 if (name_literal == STATIC_CHAR_VECTOR("sourceURL")) { |
334 value = &source_url_; | 334 value = &source_url_; |
335 } else if (name_literal == STATIC_ASCII_VECTOR("sourceMappingURL")) { | 335 } else if (name_literal == STATIC_CHAR_VECTOR("sourceMappingURL")) { |
336 value = &source_mapping_url_; | 336 value = &source_mapping_url_; |
337 } else { | 337 } else { |
338 return; | 338 return; |
339 } | 339 } |
340 if (c0_ != '=') | 340 if (c0_ != '=') |
341 return; | 341 return; |
342 Advance(); | 342 Advance(); |
343 value->Reset(); | 343 value->Reset(); |
344 while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) { | 344 while (c0_ >= 0 && unicode_cache_->IsWhiteSpace(c0_)) { |
345 Advance(); | 345 Advance(); |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1298 if (digit > '9' - '0') return false; | 1298 if (digit > '9' - '0') return false; |
1299 invalid_last_digit = (digit == 0); | 1299 invalid_last_digit = (digit == 0); |
1300 pos++; | 1300 pos++; |
1301 } | 1301 } |
1302 return !invalid_last_digit; | 1302 return !invalid_last_digit; |
1303 } | 1303 } |
1304 | 1304 |
1305 | 1305 |
1306 uint32_t DuplicateFinder::Hash(Vector<const uint8_t> key, bool is_one_byte) { | 1306 uint32_t DuplicateFinder::Hash(Vector<const uint8_t> key, bool is_one_byte) { |
1307 // Primitive hash function, almost identical to the one used | 1307 // Primitive hash function, almost identical to the one used |
1308 // for strings (except that it's seeded by the length and ASCII-ness). | 1308 // for strings (except that it's seeded by the length and representation). |
1309 int length = key.length(); | 1309 int length = key.length(); |
1310 uint32_t hash = (length << 1) | (is_one_byte ? 1 : 0) ; | 1310 uint32_t hash = (length << 1) | (is_one_byte ? 1 : 0) ; |
1311 for (int i = 0; i < length; i++) { | 1311 for (int i = 0; i < length; i++) { |
1312 uint32_t c = key[i]; | 1312 uint32_t c = key[i]; |
1313 hash = (hash + c) * 1025; | 1313 hash = (hash + c) * 1025; |
1314 hash ^= (hash >> 6); | 1314 hash ^= (hash >> 6); |
1315 } | 1315 } |
1316 return hash; | 1316 return hash; |
1317 } | 1317 } |
1318 | 1318 |
1319 | 1319 |
1320 bool DuplicateFinder::Match(void* first, void* second) { | 1320 bool DuplicateFinder::Match(void* first, void* second) { |
1321 // Decode lengths. | 1321 // Decode lengths. |
1322 // Length + ASCII-bit is encoded as base 128, most significant heptet first, | 1322 // Length + representation is encoded as base 128, most significant heptet |
1323 // with a 8th bit being non-zero while there are more heptets. | 1323 // first, with a 8th bit being non-zero while there are more heptets. |
1324 // The value encodes the number of bytes following, and whether the original | 1324 // The value encodes the number of bytes following, and whether the original |
1325 // was ASCII. | 1325 // was Latin1. |
1326 byte* s1 = reinterpret_cast<byte*>(first); | 1326 byte* s1 = reinterpret_cast<byte*>(first); |
1327 byte* s2 = reinterpret_cast<byte*>(second); | 1327 byte* s2 = reinterpret_cast<byte*>(second); |
1328 uint32_t length_one_byte_field = 0; | 1328 uint32_t length_one_byte_field = 0; |
1329 byte c1; | 1329 byte c1; |
1330 do { | 1330 do { |
1331 c1 = *s1; | 1331 c1 = *s1; |
1332 if (c1 != *s2) return false; | 1332 if (c1 != *s2) return false; |
1333 length_one_byte_field = (length_one_byte_field << 7) | (c1 & 0x7f); | 1333 length_one_byte_field = (length_one_byte_field << 7) | (c1 & 0x7f); |
1334 s1++; | 1334 s1++; |
1335 s2++; | 1335 s2++; |
(...skipping 24 matching lines...) Expand all Loading... |
1360 } | 1360 } |
1361 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1361 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1362 } | 1362 } |
1363 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1363 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1364 | 1364 |
1365 backing_store_.AddBlock(bytes); | 1365 backing_store_.AddBlock(bytes); |
1366 return backing_store_.EndSequence().start(); | 1366 return backing_store_.EndSequence().start(); |
1367 } | 1367 } |
1368 | 1368 |
1369 } } // namespace v8::internal | 1369 } } // namespace v8::internal |
OLD | NEW |