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

Side by Side Diff: third_party/WebKit/Source/wtf/StringHasher.h

Issue 2585673002: Replace ASSERT, ENABLE(ASSERT), and ASSERT_NOT_REACHED in wtf (Closed)
Patch Set: Fix an Asan issue with LinkedHashSetNodeBase::unlink Created 4 years 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 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008, 2010, 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008, 2010, 2013 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com> 3 * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 StringHasher() 49 StringHasher()
50 : m_hash(stringHashingStartValue), 50 : m_hash(stringHashingStartValue),
51 m_hasPendingCharacter(false), 51 m_hasPendingCharacter(false),
52 m_pendingCharacter(0) {} 52 m_pendingCharacter(0) {}
53 53
54 // The hasher hashes two characters at a time, and thus an "aligned" hasher is 54 // The hasher hashes two characters at a time, and thus an "aligned" hasher is
55 // one where an even number of characters have been added. Callers that 55 // one where an even number of characters have been added. Callers that
56 // always add characters two at a time can use the "assuming aligned" 56 // always add characters two at a time can use the "assuming aligned"
57 // functions. 57 // functions.
58 void addCharactersAssumingAligned(UChar a, UChar b) { 58 void addCharactersAssumingAligned(UChar a, UChar b) {
59 ASSERT(!m_hasPendingCharacter); 59 DCHECK(!m_hasPendingCharacter);
60 m_hash += a; 60 m_hash += a;
61 m_hash = (m_hash << 16) ^ ((b << 11) ^ m_hash); 61 m_hash = (m_hash << 16) ^ ((b << 11) ^ m_hash);
62 m_hash += m_hash >> 11; 62 m_hash += m_hash >> 11;
63 } 63 }
64 64
65 void addCharacter(UChar character) { 65 void addCharacter(UChar character) {
66 if (m_hasPendingCharacter) { 66 if (m_hasPendingCharacter) {
67 m_hasPendingCharacter = false; 67 m_hasPendingCharacter = false;
68 addCharactersAssumingAligned(m_pendingCharacter, character); 68 addCharactersAssumingAligned(m_pendingCharacter, character);
69 return; 69 return;
70 } 70 }
71 71
72 m_pendingCharacter = character; 72 m_pendingCharacter = character;
73 m_hasPendingCharacter = true; 73 m_hasPendingCharacter = true;
74 } 74 }
75 75
76 void addCharacters(UChar a, UChar b) { 76 void addCharacters(UChar a, UChar b) {
77 if (m_hasPendingCharacter) { 77 if (m_hasPendingCharacter) {
78 #if ENABLE(ASSERT) 78 #if DCHECK_IS_ON()
79 m_hasPendingCharacter = false; 79 m_hasPendingCharacter = false;
80 #endif 80 #endif
81 addCharactersAssumingAligned(m_pendingCharacter, a); 81 addCharactersAssumingAligned(m_pendingCharacter, a);
82 m_pendingCharacter = b; 82 m_pendingCharacter = b;
83 #if ENABLE(ASSERT) 83 #if DCHECK_IS_ON()
84 m_hasPendingCharacter = true; 84 m_hasPendingCharacter = true;
85 #endif 85 #endif
86 return; 86 return;
87 } 87 }
88 88
89 addCharactersAssumingAligned(a, b); 89 addCharactersAssumingAligned(a, b);
90 } 90 }
91 91
92 template <typename T, UChar Converter(T)> 92 template <typename T, UChar Converter(T)>
93 void addCharactersAssumingAligned(const T* data, unsigned length) { 93 void addCharactersAssumingAligned(const T* data, unsigned length) {
94 ASSERT(!m_hasPendingCharacter); 94 DCHECK(!m_hasPendingCharacter);
95 95
96 bool remainder = length & 1; 96 bool remainder = length & 1;
97 length >>= 1; 97 length >>= 1;
98 98
99 while (length--) { 99 while (length--) {
100 addCharactersAssumingAligned(Converter(data[0]), Converter(data[1])); 100 addCharactersAssumingAligned(Converter(data[0]), Converter(data[1]));
101 data += 2; 101 data += 2;
102 } 102 }
103 103
104 if (remainder) 104 if (remainder)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 template <typename T> 177 template <typename T>
178 static unsigned computeHash(const T* data, unsigned length) { 178 static unsigned computeHash(const T* data, unsigned length) {
179 return computeHash<T, defaultConverter>(data, length); 179 return computeHash<T, defaultConverter>(data, length);
180 } 180 }
181 181
182 static unsigned hashMemory(const void* data, unsigned length) { 182 static unsigned hashMemory(const void* data, unsigned length) {
183 // FIXME: Why does this function use the version of the hash that drops the 183 // FIXME: Why does this function use the version of the hash that drops the
184 // top 8 bits? We want that for all string hashing so we can use those 184 // top 8 bits? We want that for all string hashing so we can use those
185 // bits in StringImpl and hash strings consistently, but I don't see why 185 // bits in StringImpl and hash strings consistently, but I don't see why
186 // we'd want that for general memory hashing. 186 // we'd want that for general memory hashing.
187 ASSERT(!(length % 2)); 187 DCHECK(!(length % 2));
188 return computeHashAndMaskTop8Bits<UChar>(static_cast<const UChar*>(data), 188 return computeHashAndMaskTop8Bits<UChar>(static_cast<const UChar*>(data),
189 length / sizeof(UChar)); 189 length / sizeof(UChar));
190 } 190 }
191 191
192 template <size_t length> 192 template <size_t length>
193 static unsigned hashMemory(const void* data) { 193 static unsigned hashMemory(const void* data) {
194 static_assert(!(length % 2), "length must be a multiple of two"); 194 static_assert(!(length % 2), "length must be a multiple of two");
195 return hashMemory(data, length); 195 return hashMemory(data, length);
196 } 196 }
197 197
(...skipping 25 matching lines...) Expand all
223 unsigned m_hash; 223 unsigned m_hash;
224 bool m_hasPendingCharacter; 224 bool m_hasPendingCharacter;
225 UChar m_pendingCharacter; 225 UChar m_pendingCharacter;
226 }; 226 };
227 227
228 } // namespace WTF 228 } // namespace WTF
229 229
230 using WTF::StringHasher; 230 using WTF::StringHasher;
231 231
232 #endif // WTF_StringHasher_h 232 #endif // WTF_StringHasher_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/wtf/StdLibExtras.h ('k') | third_party/WebKit/Source/wtf/TerminatedArrayBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698