diff options
author | Roberto Raggi <[email protected]> | 2009-09-07 13:39:46 +0200 |
---|---|---|
committer | Roberto Raggi <[email protected]> | 2009-09-23 16:52:41 +0200 |
commit | 6c347a12c66793db50bb180b3a0ad2ea8c38f6f9 (patch) | |
tree | 041e3eff4b52cabc36643f85d59d8cfd3659c878 /src/shared | |
parent | 8848be4caae3e7bbdb3a7cee7949336990a46941 (diff) |
Introduced LiteralTable::findLiteral() and Control::findIdentifier()
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cplusplus/Control.cpp | 3 | ||||
-rw-r--r-- | src/shared/cplusplus/Control.h | 2 | ||||
-rw-r--r-- | src/shared/cplusplus/LiteralTable.h | 16 |
3 files changed, 20 insertions, 1 deletions
diff --git a/src/shared/cplusplus/Control.cpp b/src/shared/cplusplus/Control.cpp index fce76e32ad8..fda1c3b32b7 100644 --- a/src/shared/cplusplus/Control.cpp +++ b/src/shared/cplusplus/Control.cpp @@ -582,6 +582,9 @@ DiagnosticClient *Control::diagnosticClient() const void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient) { d->diagnosticClient = diagnosticClient; } +Identifier *Control::findIdentifier(const char *chars, unsigned size) const +{ return d->identifiers.findLiteral(chars, size); } + Identifier *Control::findOrInsertIdentifier(const char *chars, unsigned size) { return d->identifiers.findOrInsertLiteral(chars, size); } diff --git a/src/shared/cplusplus/Control.h b/src/shared/cplusplus/Control.h index 7698e0b226b..beb18aab4fe 100644 --- a/src/shared/cplusplus/Control.h +++ b/src/shared/cplusplus/Control.h @@ -166,6 +166,8 @@ public: /// Creates a new Objective-C method symbol. ObjCMethod *newObjCMethod(unsigned sourceLocation, Name *name = 0); + Identifier *findIdentifier(const char *chars, unsigned size) const; + Identifier *findOrInsertIdentifier(const char *chars, unsigned size); Identifier *findOrInsertIdentifier(const char *chars); diff --git a/src/shared/cplusplus/LiteralTable.h b/src/shared/cplusplus/LiteralTable.h index 67d074eca63..64fd2e1dac5 100644 --- a/src/shared/cplusplus/LiteralTable.h +++ b/src/shared/cplusplus/LiteralTable.h @@ -101,7 +101,21 @@ public: iterator end() const { return _literals + _literalCount + 1; } - _Literal *findOrInsertLiteral(const char *chars, unsigned size) + _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; + } + + _Literal *findOrInsertLiteral(const char *chars, unsigned size) { if (_buckets) { unsigned h = _Literal::hashCode(chars, size); |