X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/93a3786624b2768d89bfa27e46598dc64e2fb70a..cb9aa2694aba0ae4f946ed34b8e0f6c99c1cfe44:/bytecode/CodeBlockHash.cpp?ds=sidebyside diff --git a/bytecode/CodeBlockHash.cpp b/bytecode/CodeBlockHash.cpp index 7c890cc..87c092f 100644 --- a/bytecode/CodeBlockHash.cpp +++ b/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 +#include 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 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(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 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