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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp

Issue 2226863003: [DevTools] Reduce API surface of String16. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 4 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
OLDNEW
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/inspector_protocol/Collections.h" 7 #include "platform/inspector_protocol/Collections.h"
8 #include "platform/inspector_protocol/Platform.h" 8 #include "platform/inspector_protocol/Platform.h"
9 #include "platform/v8_inspector/V8StringUtil.h" 9 #include "platform/v8_inspector/V8StringUtil.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 static const LChar hexDigits[17] = "0123456789ABCDEF"; 13 static const char hexDigits[17] = "0123456789ABCDEF";
14 14
15 static void appendUnsignedAsHex(unsigned number, String16Builder* destination) 15 static void appendUnsignedAsHex(unsigned number, String16Builder* destination)
16 { 16 {
17 for (size_t i = 0; i < 8; ++i) { 17 for (size_t i = 0; i < 8; ++i) {
18 destination->append(hexDigits[number & 0xF]); 18 UChar c = hexDigits[number & 0xF];
19 destination->append(c);
19 number >>= 4; 20 number >>= 4;
20 } 21 }
21 } 22 }
22 23
23 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in 24 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in
24 // eingeschränkten Branchingprogrammmodellen" by Woelfe. 25 // eingeschränkten Branchingprogrammmodellen" by Woelfe.
25 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000 26 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000
26 static String16 calculateHash(const String16& str) 27 static String16 calculateHash(const String16& str)
27 { 28 {
28 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 }; 29 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 };
29 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; 30 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 };
30 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 }; 31 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 };
31 32
32 uint64_t hashes[] = { 0, 0, 0, 0, 0 }; 33 uint64_t hashes[] = { 0, 0, 0, 0, 0 };
33 uint64_t zi[] = { 1, 1, 1, 1, 1 }; 34 uint64_t zi[] = { 1, 1, 1, 1, 1 };
34 35
35 const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes); 36 const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes);
36 37
37 size_t current = 0; 38 size_t current = 0;
38 const uint32_t* data = nullptr; 39 const uint32_t* data = nullptr;
40 size_t sizeInBytes = sizeof(UChar) * str.length();
39 data = reinterpret_cast<const uint32_t*>(str.characters16()); 41 data = reinterpret_cast<const uint32_t*>(str.characters16());
40 size_t charactersSizeInBytes = str.charactersSizeInBytes(); 42 for (size_t i = 0; i < sizeInBytes / 4; i += 4) {
41 for (size_t i = 0; i < charactersSizeInBytes / 4; i += 4) {
42 uint32_t v = data[i]; 43 uint32_t v = data[i];
43 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; 44 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
44 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; 45 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
45 zi[current] = (zi[current] * random[current]) % prime[current]; 46 zi[current] = (zi[current] * random[current]) % prime[current];
46 current = current == hashesSize - 1 ? 0 : current + 1; 47 current = current == hashesSize - 1 ? 0 : current + 1;
47 } 48 }
48 if (charactersSizeInBytes % 4) { 49 if (sizeInBytes % 4) {
49 uint32_t v = 0; 50 uint32_t v = 0;
50 for (size_t i = charactersSizeInBytes - charactersSizeInBytes % 4; i < c haractersSizeInBytes; ++i) { 51 for (size_t i = sizeInBytes - sizeInBytes % 4; i < sizeInBytes; ++i) {
51 v <<= 8; 52 v <<= 8;
52 v |= reinterpret_cast<const uint8_t*>(data)[i]; 53 v |= reinterpret_cast<const uint8_t*>(data)[i];
53 } 54 }
54 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; 55 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
55 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; 56 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
56 zi[current] = (zi[current] * random[current]) % prime[current]; 57 zi[current] = (zi[current] * random[current]) % prime[current];
57 current = current == hashesSize - 1 ? 0 : current + 1; 58 current = current == hashesSize - 1 ? 0 : current + 1;
58 } 59 }
59 60
60 for (size_t i = 0; i < hashesSize; ++i) 61 for (size_t i = 0; i < hashesSize; ++i)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 m_sourceMappingURL = sourceMappingURL; 114 m_sourceMappingURL = sourceMappingURL;
114 } 115 }
115 116
116 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce) 117 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce)
117 { 118 {
118 m_source.Reset(isolate, source); 119 m_source.Reset(isolate, source);
119 m_hash = calculateHash(toProtocolString(source)); 120 m_hash = calculateHash(toProtocolString(source));
120 } 121 }
121 122
122 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698