forked from qt-creator/qt-creator
CPlusPlus: Make Environment::hashCode more local.
The function call itself shows in the critical path. Let's shave off a few cycles by making it easier inlinable. Change-Id: I14b06de27e99fa00f3be757193f2037792b18e01 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -54,7 +54,18 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
namespace CPlusPlus {
|
||||
|
||||
static unsigned hashCode(const char *str, int length)
|
||||
{
|
||||
unsigned hash_value = 0;
|
||||
|
||||
for (int i = 0; i < length; ++i)
|
||||
hash_value = (hash_value << 5) - hash_value + str[i];
|
||||
|
||||
return hash_value;
|
||||
}
|
||||
|
||||
|
||||
Environment::Environment()
|
||||
: currentLine(0),
|
||||
@@ -93,7 +104,8 @@ Macro *Environment::bind(const Macro &__macro)
|
||||
Q_ASSERT(! __macro.name().isEmpty());
|
||||
|
||||
Macro *m = new Macro (__macro);
|
||||
m->_hashcode = hashCode(m->name());
|
||||
const QByteArray &name = m->name();
|
||||
m->_hashcode = hashCode(name.begin(), name.size());
|
||||
|
||||
if (++_macro_count == _allocated_macros) {
|
||||
if (! _allocated_macros)
|
||||
@@ -223,7 +235,7 @@ Macro *Environment::resolve(const ByteArrayRef &name) const
|
||||
if (! _macros)
|
||||
return 0;
|
||||
|
||||
Macro *it = _hash[hashCode(name) % _hash_count];
|
||||
Macro *it = _hash[hashCode(name.start(), name.size()) % _hash_count];
|
||||
for (; it; it = it->_next) {
|
||||
if (it->name() != name)
|
||||
continue;
|
||||
@@ -234,26 +246,6 @@ Macro *Environment::resolve(const ByteArrayRef &name) const
|
||||
return it;
|
||||
}
|
||||
|
||||
unsigned Environment::hashCode(const QByteArray &s)
|
||||
{
|
||||
unsigned hash_value = 0;
|
||||
|
||||
for (int i = 0; i < s.size (); ++i)
|
||||
hash_value = (hash_value << 5) - hash_value + s.at (i);
|
||||
|
||||
return hash_value;
|
||||
}
|
||||
|
||||
unsigned Environment::hashCode(const ByteArrayRef &s)
|
||||
{
|
||||
unsigned hash_value = 0;
|
||||
|
||||
for (int i = 0; i < s.length(); ++i)
|
||||
hash_value = (hash_value << 5) - hash_value + s.at(i);
|
||||
|
||||
return hash_value;
|
||||
}
|
||||
|
||||
void Environment::rehash()
|
||||
{
|
||||
if (_hash) {
|
||||
@@ -278,3 +270,5 @@ void Environment::dump() const
|
||||
qDebug() << m->decoratedName();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace CPlusPlus
|
||||
|
||||
@@ -87,8 +87,6 @@ public:
|
||||
void dump() const;
|
||||
|
||||
private:
|
||||
static unsigned hashCode(const QByteArray &s);
|
||||
static unsigned hashCode(const ByteArrayRef &s);
|
||||
void rehash();
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user