summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/bytecode/CodeBlockHash.cpp
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-05-30 12:48:17 +0200
committerOswald Buddenhagen <oswald.buddenhagen@qt.io>2017-05-30 12:48:17 +0200
commit881da28418d380042aa95a97f0cbd42560a64f7c (patch)
treea794dff3274695e99c651902dde93d934ea7a5af /Source/JavaScriptCore/bytecode/CodeBlockHash.cpp
parent7e104c57a70fdf551bb3d22a5d637cdcbc69dbea (diff)
parent0fcedcd17cc00d3dd44c718b3cb36c1033319671 (diff)
downloadqtwebkit-881da28418d380042aa95a97f0cbd42560a64f7c.tar.gz
Merge 'wip/next' into dev
Change-Id: Iff9ee5e23bb326c4371ec8ed81d56f2f05d680e9
Diffstat (limited to 'Source/JavaScriptCore/bytecode/CodeBlockHash.cpp')
-rw-r--r--Source/JavaScriptCore/bytecode/CodeBlockHash.cpp45
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