From 2d93ceb6db699449650ca6c793d5dca6c0bc21db Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Fri, 7 Apr 2017 00:12:53 -0700 Subject: [PATCH] simplify some code, remove unused class --- src/query.cc | 86 ++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/src/query.cc b/src/query.cc index 4799145e..34a1d6c8 100644 --- a/src/query.cc +++ b/src/query.cc @@ -32,14 +32,7 @@ struct IdGlobalizer { -template -std::vector Transform(const std::vector& input, std::function op) { - std::vector result; - result.reserve(input.size()); - for (const In& in : input) - result.push_back(op(in)); - return result; -} + Usr MapIdToUsr(const IdCache& id_cache, const IndexTypeId& id) { @@ -57,37 +50,42 @@ Usr MapIdToUsr(const IdCache& id_cache, const IndexVarId& id) { QueryableLocation MapIdToUsr(const IdCache& id_cache, const Range& range) { return QueryableLocation(id_cache.primary_file, range); } +UsrRef MapIdToUsr(const IdCache& id_cache, const FuncRef& id) { + assert(id_cache.func_id_to_usr.find(id.id) != id_cache.func_id_to_usr.end()); + return UsrRef( + id_cache.func_id_to_usr.find(id.id)->second /*usr*/, + MapIdToUsr(id_cache, id.loc) /*loc*/); +} + +// Mapps for vectors of elements. We have to explicitly instantiate each +// template instance because C++ cannot deduce the return type template +// parameter. +template +std::vector Transform(const IdCache& id_cache, const std::vector& input) { + std::vector result; + result.reserve(input.size()); + for (const In& in : input) + result.push_back(MapIdToUsr(id_cache, in)); + return result; +} std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](IndexTypeId id) { - assert(id_cache.type_id_to_usr.find(id) != id_cache.type_id_to_usr.end()); - return id_cache.type_id_to_usr.find(id)->second; - }); + return Transform(id_cache, ids); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](IndexFuncId id) { - assert(id_cache.func_id_to_usr.find(id) != id_cache.func_id_to_usr.end()); - return id_cache.func_id_to_usr.find(id)->second; - }); + return Transform(id_cache, ids); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](IndexVarId id) { - assert(id_cache.var_id_to_usr.find(id) != id_cache.var_id_to_usr.end()); - return id_cache.var_id_to_usr.find(id)->second; - }); + return Transform(id_cache, ids); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](FuncRef ref) { - assert(id_cache.func_id_to_usr.find(ref.id) != id_cache.func_id_to_usr.end()); - return UsrRef( - id_cache.func_id_to_usr.find(ref.id)->second /*usr*/, - MapIdToUsr(id_cache, ref.loc) /*loc*/); - }); + return Transform(id_cache, ids); } std::vector MapIdToUsr(const IdCache& id_cache, const std::vector& ids) { - return Transform(ids, [&](Range range) { - return QueryableLocation(id_cache.primary_file, range); - }); + return Transform(id_cache, ids); } + + + QueryableTypeDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const IndexedTypeDef::Def& def) { QueryableTypeDef::DefUpdate result(def.usr); result.short_name = def.short_name; @@ -137,6 +135,18 @@ QueryableVarDef::DefUpdate MapIdToUsr(const IdCache& id_cache, const IndexedVarD return result; } + + + + + + + + + + + + QueryableFile::Def BuildFileDef(const IndexedFile& indexed) { QueryableFile::Def def; def.usr = indexed.path; @@ -218,25 +228,7 @@ QueryableVarDef::QueryableVarDef(IdCache& id_cache, const IndexedVarDef& indexed -// TODO: For space reasons, it may make sense to map Usr -> offset inside of global storage. But not for intermediate or disk-storage. -// We can probably eliminate most of that pain by coming up with our own UsrDb concept which interns the Usr strings. We can make -// the pain of a global UsrDb less by -// (parallel)clangindex -> (main)commit USRs to global -> (parallel)transfer IDs to global USRs -> (main)import -struct CachedIndexedFile { - // Path to the file indexed. - std::string path; - - // TODO: Make sure that |previous_index| and |current_index| use the same id - // to USR mapping. This lets us greatly speed up difference computation. - - // The previous index. This is used for index updates, so we only apply a - // an update diff when changing the global db. - optional previous_index; - IndexedFile current_index; - - CachedIndexedFile(const IndexedFile& indexed) : current_index(indexed) {} -}; template void AddRange(std::vector* dest, const std::vector& to_add) {