Factor the trait for lookup into the on-based hash table of
identifiers into two parts: the part that involves dealing with the key (which can be re-used) and the ASTReader-specific part that creates the IdentifierInfos. While I'm at it, StringRef'ify this code, which was using pair<const char*, unsigned>. No functionality change. llvm-svn: 173283
This commit is contained in:
parent
cc8fbbf129
commit
bfd73d74b9
|
@ -440,22 +440,22 @@ ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d,
|
|||
return Result;
|
||||
}
|
||||
|
||||
unsigned ASTIdentifierLookupTrait::ComputeHash(const internal_key_type& a) {
|
||||
return llvm::HashString(StringRef(a.first, a.second));
|
||||
unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) {
|
||||
return llvm::HashString(a);
|
||||
}
|
||||
|
||||
std::pair<unsigned, unsigned>
|
||||
ASTIdentifierLookupTrait::ReadKeyDataLength(const unsigned char*& d) {
|
||||
ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) {
|
||||
using namespace clang::io;
|
||||
unsigned DataLen = ReadUnalignedLE16(d);
|
||||
unsigned KeyLen = ReadUnalignedLE16(d);
|
||||
return std::make_pair(KeyLen, DataLen);
|
||||
}
|
||||
|
||||
std::pair<const char*, unsigned>
|
||||
ASTIdentifierLookupTrait::ReadKey(const unsigned char* d, unsigned n) {
|
||||
ASTIdentifierLookupTraitBase::internal_key_type
|
||||
ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) {
|
||||
assert(n >= 2 && d[n-1] == '\0');
|
||||
return std::make_pair((const char*) d, n-1);
|
||||
return StringRef((const char*) d, n-1);
|
||||
}
|
||||
|
||||
IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
||||
|
@ -474,7 +474,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
|||
// and associate it with the persistent ID.
|
||||
IdentifierInfo *II = KnownII;
|
||||
if (!II) {
|
||||
II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second));
|
||||
II = &Reader.getIdentifierTable().getOwn(k);
|
||||
KnownII = II;
|
||||
}
|
||||
Reader.SetIdentifierInfo(ID, II);
|
||||
|
@ -503,7 +503,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
|
|||
// the new IdentifierInfo.
|
||||
IdentifierInfo *II = KnownII;
|
||||
if (!II) {
|
||||
II = &Reader.getIdentifierTable().getOwn(StringRef(k.first, k.second));
|
||||
II = &Reader.getIdentifierTable().getOwn(StringRef(k));
|
||||
KnownII = II;
|
||||
}
|
||||
Reader.markIdentifierUpToDate(II);
|
||||
|
@ -1398,9 +1398,7 @@ namespace {
|
|||
ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(),
|
||||
M, This->Found);
|
||||
|
||||
std::pair<const char*, unsigned> Key(This->Name.begin(),
|
||||
This->Name.size());
|
||||
ASTIdentifierLookupTable::iterator Pos = IdTable->find(Key, &Trait);
|
||||
ASTIdentifierLookupTable::iterator Pos = IdTable->find(This->Name, &Trait);
|
||||
if (Pos == IdTable->end())
|
||||
return false;
|
||||
|
||||
|
@ -5745,9 +5743,9 @@ StringRef ASTIdentifierIterator::Next() {
|
|||
|
||||
// We have any identifiers remaining in the current AST file; return
|
||||
// the next one.
|
||||
std::pair<const char*, unsigned> Key = *Current;
|
||||
StringRef Result = *Current;
|
||||
++Current;
|
||||
return StringRef(Key.first, Key.second);
|
||||
return Result;
|
||||
}
|
||||
|
||||
IdentifierIterator *ASTReader::getIdentifiers() const {
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
|
||||
#define LLVM_CLANG_SERIALIZATION_ASTREADER_INTERNALS_H
|
||||
|
||||
#include "ASTReaderInternals.h"
|
||||
#include "clang/AST/DeclarationName.h"
|
||||
#include "clang/Basic/OnDiskHashTable.h"
|
||||
#include "clang/Serialization/ASTBitCodes.h"
|
||||
#include "llvm/Support/Endian.h"
|
||||
#include <sys/stat.h>
|
||||
#include <utility>
|
||||
|
@ -78,8 +78,43 @@ public:
|
|||
unsigned DataLen);
|
||||
};
|
||||
|
||||
/// \brief Base class for the trait describing the on-disk hash table for the
|
||||
/// identifiers in an AST file.
|
||||
///
|
||||
/// This class is not useful by itself; rather, it provides common
|
||||
/// functionality for accessing the on-disk hash table of identifiers
|
||||
/// in an AST file. Different subclasses customize that functionality
|
||||
/// based on what information they are interested in. Those subclasses
|
||||
/// must provide the \c data_type typedef and the ReadData operation,
|
||||
/// only.
|
||||
class ASTIdentifierLookupTraitBase {
|
||||
public:
|
||||
typedef StringRef external_key_type;
|
||||
typedef StringRef internal_key_type;
|
||||
|
||||
|
||||
static bool EqualKey(const internal_key_type& a, const internal_key_type& b) {
|
||||
return a == b;
|
||||
}
|
||||
|
||||
static unsigned ComputeHash(const internal_key_type& a);
|
||||
|
||||
static std::pair<unsigned, unsigned>
|
||||
ReadKeyDataLength(const unsigned char*& d);
|
||||
|
||||
// This hopefully will just get inlined and removed by the optimizer.
|
||||
static const internal_key_type&
|
||||
GetInternalKey(const external_key_type& x) { return x; }
|
||||
|
||||
// This hopefully will just get inlined and removed by the optimizer.
|
||||
static const external_key_type&
|
||||
GetExternalKey(const internal_key_type& x) { return x; }
|
||||
|
||||
static internal_key_type ReadKey(const unsigned char* d, unsigned n);
|
||||
};
|
||||
|
||||
/// \brief Class that performs lookup for an identifier stored in an AST file.
|
||||
class ASTIdentifierLookupTrait {
|
||||
class ASTIdentifierLookupTrait : public ASTIdentifierLookupTraitBase {
|
||||
ASTReader &Reader;
|
||||
ModuleFile &F;
|
||||
|
||||
|
@ -91,42 +126,15 @@ class ASTIdentifierLookupTrait {
|
|||
public:
|
||||
typedef IdentifierInfo * data_type;
|
||||
|
||||
typedef const std::pair<const char*, unsigned> external_key_type;
|
||||
|
||||
typedef external_key_type internal_key_type;
|
||||
|
||||
ASTIdentifierLookupTrait(ASTReader &Reader, ModuleFile &F,
|
||||
IdentifierInfo *II = 0)
|
||||
: Reader(Reader), F(F), KnownII(II) { }
|
||||
|
||||
static bool EqualKey(const internal_key_type& a,
|
||||
const internal_key_type& b) {
|
||||
return (a.second == b.second) ? memcmp(a.first, b.first, a.second) == 0
|
||||
: false;
|
||||
}
|
||||
|
||||
static unsigned ComputeHash(const internal_key_type& a);
|
||||
|
||||
// This hopefully will just get inlined and removed by the optimizer.
|
||||
static const internal_key_type&
|
||||
GetInternalKey(const external_key_type& x) { return x; }
|
||||
|
||||
// This hopefully will just get inlined and removed by the optimizer.
|
||||
static const external_key_type&
|
||||
GetExternalKey(const internal_key_type& x) { return x; }
|
||||
|
||||
static std::pair<unsigned, unsigned>
|
||||
ReadKeyDataLength(const unsigned char*& d);
|
||||
|
||||
static std::pair<const char*, unsigned>
|
||||
ReadKey(const unsigned char* d, unsigned n);
|
||||
|
||||
IdentifierInfo *ReadData(const internal_key_type& k,
|
||||
const unsigned char* d,
|
||||
unsigned DataLen);
|
||||
|
||||
data_type ReadData(const internal_key_type& k,
|
||||
const unsigned char* d,
|
||||
unsigned DataLen);
|
||||
|
||||
ASTReader &getReader() const { return Reader; }
|
||||
|
||||
};
|
||||
|
||||
/// \brief The on-disk hash table used to contain information about
|
||||
|
|
Loading…
Reference in New Issue