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

Introduced LiteralTable::findLiteral() and Control::findIdentifier()

parent 8848be4c
No related branches found
No related tags found
No related merge requests found
...@@ -582,6 +582,9 @@ DiagnosticClient *Control::diagnosticClient() const ...@@ -582,6 +582,9 @@ DiagnosticClient *Control::diagnosticClient() const
void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient) void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient)
{ d->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) Identifier *Control::findOrInsertIdentifier(const char *chars, unsigned size)
{ return d->identifiers.findOrInsertLiteral(chars, size); } { return d->identifiers.findOrInsertLiteral(chars, size); }
......
...@@ -166,6 +166,8 @@ public: ...@@ -166,6 +166,8 @@ public:
/// Creates a new Objective-C method symbol. /// Creates a new Objective-C method symbol.
ObjCMethod *newObjCMethod(unsigned sourceLocation, Name *name = 0); 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, unsigned size);
Identifier *findOrInsertIdentifier(const char *chars); Identifier *findOrInsertIdentifier(const char *chars);
......
...@@ -101,7 +101,21 @@ public: ...@@ -101,7 +101,21 @@ public:
iterator end() const iterator end() const
{ return _literals + _literalCount + 1; } { 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) { if (_buckets) {
unsigned h = _Literal::hashCode(chars, size); unsigned h = _Literal::hashCode(chars, size);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment