summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/PreprocessorEnvironment.cpp
diff options
context:
space:
mode:
authorhjk <hjk121@nokiamail.com>2013-10-05 23:51:52 +0200
committerhjk <hjk121@nokiamail.com>2013-10-07 21:05:31 +0200
commit4258715731758694100c08720e6358c96a104d85 (patch)
treef5ad6d1ead1c86d297615280cb8f5d9724c6eea8 /src/libs/cplusplus/PreprocessorEnvironment.cpp
parentffa61e4ced5f77846bef2d9a97ba597fdc0917e3 (diff)
downloadqt-creator-4258715731758694100c08720e6358c96a104d85.tar.gz
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>
Diffstat (limited to 'src/libs/cplusplus/PreprocessorEnvironment.cpp')
-rw-r--r--src/libs/cplusplus/PreprocessorEnvironment.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/libs/cplusplus/PreprocessorEnvironment.cpp b/src/libs/cplusplus/PreprocessorEnvironment.cpp
index 23327dfefa..5760fbebd8 100644
--- a/src/libs/cplusplus/PreprocessorEnvironment.cpp
+++ b/src/libs/cplusplus/PreprocessorEnvironment.cpp
@@ -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