From 642975ea1753820aa75f977ca61ab82f9f57428d Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 1 Feb 2018 13:38:46 -0800 Subject: [PATCH] Reflect string_view and fix workspace/symbol --- src/messages/workspace_symbol.cc | 8 ++++---- src/query.cc | 4 ++-- src/query.h | 8 ++++---- src/serializer.cc | 5 ++++- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/messages/workspace_symbol.cc b/src/messages/workspace_symbol.cc index 6122b98c..03587256 100644 --- a/src/messages/workspace_symbol.cc +++ b/src/messages/workspace_symbol.cc @@ -124,8 +124,8 @@ gap_penalty(k+1, j) + score[j] : k < j)) The first dimension can be suppressed since we do not need a matching scheme, which reduces the space complexity from O(N*M) to O(M) */ -int FuzzyEvaluate(std::string_view pattern, - std::string_view str, +int FuzzyEvaluate(const std::string& pattern, + const std::string& str, std::vector& score, std::vector& dp) { bool pfirst = true, // aligning the first character of pattern @@ -204,7 +204,7 @@ struct WorkspaceSymbolHandler : BaseMessageHandler { for (int i = 0; i < db->detailed_names.size(); ++i) { if (db->detailed_names[i].find(query) != std::string::npos) { // Do not show the same entry twice. - if (!inserted_results.insert(std::string(db->detailed_names[i])).second) + if (!inserted_results.insert(db->detailed_names[i]).second) continue; if (InsertSymbolIntoResult(db, working_files, db->symbols[i], @@ -227,7 +227,7 @@ struct WorkspaceSymbolHandler : BaseMessageHandler { for (int i = 0; i < db->short_names.size(); ++i) { if (SubsequenceMatch(query_without_space, db->short_names[i])) { // Do not show the same entry twice. - if (!inserted_results.insert(std::string(db->detailed_names[i])).second) + if (!inserted_results.insert(db->detailed_names[i]).second) continue; if (InsertSymbolIntoResult(db, working_files, db->symbols[i], diff --git a/src/query.cc b/src/query.cc index 8346c084..27a41c4d 100644 --- a/src/query.cc +++ b/src/query.cc @@ -943,8 +943,8 @@ void QueryDatabase::ImportOrUpdate( void QueryDatabase::UpdateDetailedNames(size_t* qualified_name_index, SymbolKind kind, size_t symbol_index, - std::string_view short_name, - std::string_view detailed_name) { + const std::string& short_name, + const std::string& detailed_name) { if (*qualified_name_index == -1) { short_names.push_back(short_name); detailed_names.push_back(detailed_name); diff --git a/src/query.h b/src/query.h index 5ea7d25e..daee2aff 100644 --- a/src/query.h +++ b/src/query.h @@ -363,8 +363,8 @@ MAKE_HASHABLE(NormalizedPath, t.path); struct QueryDatabase { // Indicies between lookup vectors are related to symbols, ie, index 5 in // |detailed_names| matches index 5 in |symbols|. - std::vector detailed_names; - std::vector short_names; + std::vector detailed_names; + std::vector short_names; std::vector symbols; // Raw data storage. Accessible via SymbolIdx instances. @@ -390,8 +390,8 @@ struct QueryDatabase { void UpdateDetailedNames(size_t* qualified_name_index, SymbolKind kind, size_t symbol_index, - std::string_view short_name, - std::string_view detailed_name); + const std::string& short_name, + const std::string& detailed_name); // Query the indexing structure to look up symbol id for given Usr. optional GetQueryFileIdFromPath(const std::string& path); diff --git a/src/serializer.cc b/src/serializer.cc index 877b7631..a3e81bf9 100644 --- a/src/serializer.cc +++ b/src/serializer.cc @@ -119,7 +119,10 @@ void Reflect(Reader&, std::string_view&) { assert(0); } void Reflect(Writer& visitor, std::string_view& data) { - visitor.String(&data[0], (rapidjson::SizeType)data.size()); + if (data.empty()) + visitor.String(""); + else + visitor.String(&data[0], (rapidjson::SizeType)data.size()); }