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 "src/scanner.h" | 7 #include "src/scanner.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 pos++; | 1572 pos++; |
1573 } | 1573 } |
1574 return !invalid_last_digit; | 1574 return !invalid_last_digit; |
1575 } | 1575 } |
1576 | 1576 |
1577 | 1577 |
1578 uint32_t DuplicateFinder::Hash(Vector<const uint8_t> key, bool is_one_byte) { | 1578 uint32_t DuplicateFinder::Hash(Vector<const uint8_t> key, bool is_one_byte) { |
1579 // Primitive hash function, almost identical to the one used | 1579 // Primitive hash function, almost identical to the one used |
1580 // for strings (except that it's seeded by the length and representation). | 1580 // for strings (except that it's seeded by the length and representation). |
1581 int length = key.length(); | 1581 int length = key.length(); |
1582 uint32_t hash = (length << 1) | (is_one_byte ? 1 : 0) ; | 1582 uint32_t hash = (length << 1) | (is_one_byte ? 1 : 0); |
1583 for (int i = 0; i < length; i++) { | 1583 for (int i = 0; i < length; i++) { |
1584 uint32_t c = key[i]; | 1584 uint32_t c = key[i]; |
1585 hash = (hash + c) * 1025; | 1585 hash = (hash + c) * 1025; |
1586 hash ^= (hash >> 6); | 1586 hash ^= (hash >> 6); |
1587 } | 1587 } |
1588 return hash; | 1588 return hash; |
1589 } | 1589 } |
1590 | 1590 |
1591 | 1591 |
1592 bool DuplicateFinder::Match(void* first, void* second) { | 1592 bool DuplicateFinder::Match(void* first, void* second) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1633 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); | 1633 backing_store_.Add(static_cast<uint8_t>((one_byte_length >> 7) | 0x80u)); |
1634 } | 1634 } |
1635 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); | 1635 backing_store_.Add(static_cast<uint8_t>(one_byte_length & 0x7f)); |
1636 | 1636 |
1637 backing_store_.AddBlock(bytes); | 1637 backing_store_.AddBlock(bytes); |
1638 return backing_store_.EndSequence().start(); | 1638 return backing_store_.EndSequence().start(); |
1639 } | 1639 } |
1640 | 1640 |
1641 } // namespace internal | 1641 } // namespace internal |
1642 } // namespace v8 | 1642 } // namespace v8 |
OLD | NEW |