diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Source/JavaScriptCore/bytecode/CodeBlockHash.cpp | |
parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
download | qtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/JavaScriptCore/bytecode/CodeBlockHash.cpp')
-rw-r--r-- | Source/JavaScriptCore/bytecode/CodeBlockHash.cpp | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp b/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp index 7c890cc88..87c092f64 100644 --- a/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp +++ b/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012 Apple Inc. All rights reserved. + * Copyright (C) 2012, 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -28,61 +28,40 @@ #include "SourceCode.h" #include <wtf/SHA1.h> +#include <wtf/SixCharacterHash.h> namespace JSC { -#define TABLE ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") - CodeBlockHash::CodeBlockHash(const char* string) - : m_hash(0) + : m_hash(sixCharacterHashStringToInteger(string)) { - RELEASE_ASSERT(strlen(string) == 6); - - for (unsigned i = 0; i < 6; ++i) { - m_hash *= 62; - unsigned c = string[i]; - if (c >= 'A' && c <= 'Z') { - m_hash += c - 'A'; - continue; - } - if (c >= 'a' && c <= 'z') { - m_hash += c - 'a' + 26; - continue; - } - ASSERT(c >= '0' && c <= '9'); - m_hash += c - '0' + 26 * 2; - } } CodeBlockHash::CodeBlockHash(const SourceCode& sourceCode, CodeSpecializationKind kind) : m_hash(0) { SHA1 sha1; - sha1.addBytes(sourceCode.toString().utf8()); - Vector<uint8_t, 20> digest; + sha1.addBytes(sourceCode.toUTF8()); + SHA1::Digest digest; sha1.computeHash(digest); m_hash += digest[0] | (digest[1] << 8) | (digest[2] << 16) | (digest[3] << 24); m_hash ^= static_cast<unsigned>(kind); + + // Ensure that 0 corresponds to the hash not having been computed. + if (!m_hash) + m_hash = 1; } void CodeBlockHash::dump(PrintStream& out) const { - ASSERT(strlen(TABLE) == 62); - - char buffer[7]; - unsigned accumulator = m_hash; - for (unsigned i = 6; i--;) { - buffer[i] = TABLE[accumulator % 62]; - accumulator /= 62; - } - buffer[6] = 0; + std::array<char, 7> buffer = integerToSixCharacterHashString(m_hash); #if !ASSERT_DISABLED - CodeBlockHash recompute(buffer); + CodeBlockHash recompute(buffer.data()); ASSERT(recompute == *this); #endif // !ASSERT_DISABLED - out.print(buffer); + out.print(buffer.data()); } } // namespace JSC |