OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium 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 #include "platform/v8_inspector/V8DebuggerScript.h" | 5 #include "platform/v8_inspector/V8DebuggerScript.h" |
6 | 6 |
7 #include "platform/v8_inspector/V8StringUtil.h" | 7 #include "platform/v8_inspector/ProtocolPlatform.h" |
8 #include "platform/v8_inspector/StringUtil.h" | |
8 | 9 |
9 namespace v8_inspector { | 10 namespace v8_inspector { |
10 | 11 |
11 static const char hexDigits[17] = "0123456789ABCDEF"; | 12 static const char hexDigits[17] = "0123456789ABCDEF"; |
12 | 13 |
13 static void appendUnsignedAsHex(unsigned number, String16Builder* destination) | 14 static void appendUnsignedAsHex(unsigned number, String16Builder* destination) |
14 { | 15 { |
15 for (size_t i = 0; i < 8; ++i) { | 16 for (size_t i = 0; i < 8; ++i) { |
16 UChar c = hexDigits[number & 0xF]; | 17 UChar c = hexDigits[number & 0xF]; |
17 destination->append(c); | 18 destination->append(c); |
18 number >>= 4; | 19 number >>= 4; |
19 } | 20 } |
20 } | 21 } |
21 | 22 |
22 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in | 23 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in |
23 // eingeschränkten Branchingprogrammmodellen" by Woelfe. | 24 // eingeschränkten Branchingprogrammmodellen" by Woelfe. |
24 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000 | 25 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000 |
25 static String16 calculateHash(const String16& str) | 26 static String16 calculateHash(const String16& str) |
26 { | 27 { |
27 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 }; | 28 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 }; |
28 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; | 29 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; |
29 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 }; | 30 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 }; |
30 | 31 |
31 uint64_t hashes[] = { 0, 0, 0, 0, 0 }; | 32 uint64_t hashes[] = { 0, 0, 0, 0, 0 }; |
32 uint64_t zi[] = { 1, 1, 1, 1, 1 }; | 33 uint64_t zi[] = { 1, 1, 1, 1, 1 }; |
33 | 34 |
34 const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes); | 35 const size_t hashesSize = V8_INSPECTOR_ARRAY_LENGTH(hashes); |
caseq
2016/08/26 19:17:20
nit: I'd get rid of these in favor of std::end(has
dgozman
2016/08/26 21:31:27
We can do that in a follow up.
| |
35 | 36 |
36 size_t current = 0; | 37 size_t current = 0; |
37 const uint32_t* data = nullptr; | 38 const uint32_t* data = nullptr; |
38 size_t sizeInBytes = sizeof(UChar) * str.length(); | 39 size_t sizeInBytes = sizeof(UChar) * str.length(); |
39 data = reinterpret_cast<const uint32_t*>(str.characters16()); | 40 data = reinterpret_cast<const uint32_t*>(str.characters16()); |
40 for (size_t i = 0; i < sizeInBytes / 4; i += 4) { | 41 for (size_t i = 0; i < sizeInBytes / 4; i += 4) { |
41 uint32_t v = data[i]; | 42 uint32_t v = data[i]; |
42 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; | 43 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; |
43 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; | 44 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; |
44 zi[current] = (zi[current] * random[current]) % prime[current]; | 45 zi[current] = (zi[current] * random[current]) % prime[current]; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 m_sourceMappingURL = sourceMappingURL; | 112 m_sourceMappingURL = sourceMappingURL; |
112 } | 113 } |
113 | 114 |
114 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce) | 115 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce) |
115 { | 116 { |
116 m_source.Reset(isolate, source); | 117 m_source.Reset(isolate, source); |
117 m_hash = calculateHash(toProtocolString(source)); | 118 m_hash = calculateHash(toProtocolString(source)); |
118 } | 119 } |
119 | 120 |
120 } // namespace v8_inspector | 121 } // namespace v8_inspector |
OLD | NEW |