aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/cplusplus/LiteralTable.h
diff options
context:
space:
mode:
authorRoberto Raggi <[email protected]>2009-12-01 11:33:13 +0100
committerRoberto Raggi <[email protected]>2009-12-01 11:46:36 +0100
commitfade61a8a9397f44d31c5ab4ede57e5259de8880 (patch)
tree539129b8b2594cad57752f3883b4c766f1299ef6 /src/shared/cplusplus/LiteralTable.h
parentb792b934e48c741b804f19378b6028f32c1c04eb (diff)
Use const literals.
Diffstat (limited to 'src/shared/cplusplus/LiteralTable.h')
-rw-r--r--src/shared/cplusplus/LiteralTable.h94
1 files changed, 47 insertions, 47 deletions
diff --git a/src/shared/cplusplus/LiteralTable.h b/src/shared/cplusplus/LiteralTable.h
index ff4246748f9..408db390531 100644
--- a/src/shared/cplusplus/LiteralTable.h
+++ b/src/shared/cplusplus/LiteralTable.h
@@ -61,7 +61,7 @@ class LiteralTable
void operator =(const LiteralTable &other);
public:
- typedef _Literal **iterator;
+ typedef _Literal *const *iterator;
public:
LiteralTable()
@@ -74,14 +74,14 @@ public:
~LiteralTable()
{
- if (_literals) {
- _Literal **lastLiteral = _literals + _literalCount + 1;
- for (_Literal **it = _literals; it != lastLiteral; ++it)
- delete *it;
- std::free(_literals);
- }
- if (_buckets)
- std::free(_buckets);
+ if (_literals) {
+ _Literal **lastLiteral = _literals + _literalCount + 1;
+ for (_Literal **it = _literals; it != lastLiteral; ++it)
+ delete *it;
+ std::free(_literals);
+ }
+ if (_buckets)
+ std::free(_buckets);
}
bool empty() const
@@ -90,7 +90,7 @@ public:
unsigned size() const
{ return _literalCount + 1; }
- _Literal *at(unsigned index) const
+ const _Literal *at(unsigned index) const
{ return _literals[index]; }
iterator begin() const
@@ -99,53 +99,53 @@ public:
iterator end() const
{ return _literals + _literalCount + 1; }
- _Literal *findLiteral(const char *chars, unsigned size) const
+ const _Literal *findLiteral(const char *chars, unsigned size) const
{
- if (_buckets) {
- unsigned h = _Literal::hashCode(chars, size);
- _Literal *literal = _buckets[h % _allocatedBuckets];
- for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
- if (literal->size() == size && ! std::strncmp(literal->chars(), chars, size))
- return literal;
- }
- }
-
- return 0;
- }
+ if (_buckets) {
+ unsigned h = _Literal::hashCode(chars, size);
+ _Literal *literal = _buckets[h % _allocatedBuckets];
+ for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
+ if (literal->size() == size && ! std::strncmp(literal->chars(), chars, size))
+ return literal;
+ }
+ }
+
+ return 0;
+ }
- _Literal *findOrInsertLiteral(const char *chars, unsigned size)
+ const _Literal *findOrInsertLiteral(const char *chars, unsigned size)
{
- if (_buckets) {
- unsigned h = _Literal::hashCode(chars, size);
- _Literal *literal = _buckets[h % _allocatedBuckets];
- for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
- if (literal->size() == size && ! std::strncmp(literal->chars(), chars, size))
- return literal;
- }
- }
+ if (_buckets) {
+ unsigned h = _Literal::hashCode(chars, size);
+ _Literal *literal = _buckets[h % _allocatedBuckets];
+ for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
+ if (literal->size() == size && ! std::strncmp(literal->chars(), chars, size))
+ return literal;
+ }
+ }
- _Literal *literal = new _Literal(chars, size);
+ _Literal *literal = new _Literal(chars, size);
- if (++_literalCount == _allocatedLiterals) {
- _allocatedLiterals <<= 1;
+ if (++_literalCount == _allocatedLiterals) {
+ _allocatedLiterals <<= 1;
- if (! _allocatedLiterals)
- _allocatedLiterals = 256;
+ if (! _allocatedLiterals)
+ _allocatedLiterals = 256;
- _literals = (_Literal **) std::realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
- }
+ _literals = (_Literal **) std::realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
+ }
- _literals[_literalCount] = literal;
+ _literals[_literalCount] = literal;
- if (! _buckets || _literalCount >= _allocatedBuckets * .6)
- rehash();
- else {
- unsigned h = literal->hashCode() % _allocatedBuckets;
- literal->_next = _buckets[h];
- _buckets[h] = literal;
- }
+ if (! _buckets || _literalCount >= _allocatedBuckets * .6)
+ rehash();
+ else {
+ unsigned h = literal->hashCode() % _allocatedBuckets;
+ literal->_next = _buckets[h];
+ _buckets[h] = literal;
+ }
- return literal;
+ return literal;
}
protected: