Skip to content
Snippets Groups Projects
Commit 6b5c9cc7 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Cleanup

parent c4877cf6
Branches
Tags
No related merge requests found
...@@ -97,7 +97,7 @@ Macro *Environment::bind(const Macro &__macro) ...@@ -97,7 +97,7 @@ Macro *Environment::bind(const Macro &__macro)
else else
_allocated_macros <<= 1; _allocated_macros <<= 1;
_macros = (Macro **) realloc(_macros, sizeof(Macro *) * _allocated_macros); _macros = reinterpret_cast<Macro **>(realloc(_macros, sizeof(Macro *) * _allocated_macros));
} }
_macros[_macro_count] = m; _macros[_macro_count] = m;
...@@ -147,7 +147,7 @@ void Environment::reset() ...@@ -147,7 +147,7 @@ void Environment::reset()
_hash_count = 401; _hash_count = 401;
} }
bool Environment::isBuiltinMacro(const QByteArray &s) const bool Environment::isBuiltinMacro(const QByteArray &s)
{ {
if (s.length() != 8) if (s.length() != 8)
return false; return false;
...@@ -211,6 +211,12 @@ bool Environment::isBuiltinMacro(const QByteArray &s) const ...@@ -211,6 +211,12 @@ bool Environment::isBuiltinMacro(const QByteArray &s) const
return false; return false;
} }
Environment::iterator Environment::firstMacro() const
{ return _macros; }
Environment::iterator Environment::lastMacro() const
{ return _macros + _macro_count + 1; }
Macro *Environment::resolve(const QByteArray &name) const Macro *Environment::resolve(const QByteArray &name) const
{ {
if (! _macros) if (! _macros)
...@@ -244,9 +250,9 @@ void Environment::rehash() ...@@ -244,9 +250,9 @@ void Environment::rehash()
_hash_count <<= 1; _hash_count <<= 1;
} }
_hash = (Macro **) calloc(_hash_count, sizeof(Macro *)); _hash = reinterpret_cast<Macro **>(calloc(_hash_count, sizeof(Macro *)));
for (Macro **it = firstMacro(); it != lastMacro(); ++it) { for (iterator it = firstMacro(); it != lastMacro(); ++it) {
Macro *m = *it; Macro *m = *it;
const unsigned h = m->_hashcode % _hash_count; const unsigned h = m->_hashcode % _hash_count;
m->_next = _hash[h]; m->_next = _hash[h];
......
...@@ -61,6 +61,9 @@ class Macro; ...@@ -61,6 +61,9 @@ class Macro;
class CPLUSPLUS_EXPORT Environment class CPLUSPLUS_EXPORT Environment
{ {
public:
typedef Macro **iterator;
public: public:
Environment(); Environment();
~Environment(); ~Environment();
...@@ -72,23 +75,15 @@ public: ...@@ -72,23 +75,15 @@ public:
Macro *remove(const QByteArray &name); Macro *remove(const QByteArray &name);
Macro *resolve(const QByteArray &name) const; Macro *resolve(const QByteArray &name) const;
bool isBuiltinMacro(const QByteArray &name) const;
const Macro *const *firstMacro() const
{ return _macros; }
Macro **firstMacro() iterator firstMacro() const;
{ return _macros; } iterator lastMacro() const;
const Macro *const *lastMacro() const
{ return _macros + _macro_count + 1; }
Macro **lastMacro()
{ return _macros + _macro_count + 1; }
void reset(); void reset();
void addMacros(const QList<Macro> &macros); void addMacros(const QList<Macro> &macros);
static bool isBuiltinMacro(const QByteArray &name);
private: private:
static unsigned hashCode(const QByteArray &s); static unsigned hashCode(const QByteArray &s);
void rehash(); void rehash();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment