[clang-tools-extra] r342974 - [clangd] NFC: Simplify code, enforce LLVM Coding Standards

Kirill Bobyrev via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 25 06:58:48 PDT 2018


Author: omtcyfz
Date: Tue Sep 25 06:58:48 2018
New Revision: 342974

URL: http://llvm.org/viewvc/llvm-project?rev=342974&view=rev
Log:
[clangd] NFC: Simplify code, enforce LLVM Coding Standards

For consistency, functional-style code pieces are replaced with their
simple counterparts to improve readability.

Also, file headers are fixed to comply with LLVM Coding Standards.

`static` member of anonymous namespace is not marked `static` anymore,
because it is redundant.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D52466

Modified:
    clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
    clang-tools-extra/trunk/clangd/index/dex/Dex.h
    clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
    clang-tools-extra/trunk/clangd/index/dex/Iterator.h
    clang-tools-extra/trunk/clangd/index/dex/Token.h
    clang-tools-extra/trunk/clangd/index/dex/Trigram.h

Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=342974&r1=342973&r2=342974&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Tue Sep 25 06:58:48 2018
@@ -23,7 +23,7 @@ namespace dex {
 namespace {
 
 // Mark symbols which are can be used for code completion.
-static const Token RestrictedForCodeCompletion =
+const Token RestrictedForCodeCompletion =
     Token(Token::Kind::Sentinel, "Restricted For Code Completion");
 
 // Returns the tokens which are given symbol's characteristics. Currently, the

Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.h?rev=342974&r1=342973&r2=342974&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Dex.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.h Tue Sep 25 06:58:48 2018
@@ -6,15 +6,16 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//
-// This defines Dex - a symbol index implementation based on query iterators
-// over symbol tokens, such as fuzzy matching trigrams, scopes, types, etc.
-// While consuming more memory and having longer build stage due to
-// preprocessing, Dex will have substantially lower latency. It will also allow
-// efficient symbol searching which is crucial for operations like code
-// completion, and can be very important for a number of different code
-// transformations which will be eventually supported by Clangd.
-//
+///
+/// \file
+/// This defines Dex - a symbol index implementation based on query iterators
+/// over symbol tokens, such as fuzzy matching trigrams, scopes, types, etc.
+/// While consuming more memory and having longer build stage due to
+/// preprocessing, Dex will have substantially lower latency. It will also allow
+/// efficient symbol searching which is crucial for operations like code
+/// completion, and can be very important for a number of different code
+/// transformations which will be eventually supported by Clangd.
+///
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_DEX_DEX_H

Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp?rev=342974&r1=342973&r2=342974&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Tue Sep 25 06:58:48 2018
@@ -64,11 +64,10 @@ public:
 
   float consume() override {
     assert(!reachedEnd() && "AND iterator can't consume() at the end.");
-    return std::accumulate(
-        begin(Children), end(Children), DEFAULT_BOOST_SCORE,
-        [&](float Current, const std::unique_ptr<Iterator> &Child) {
-          return Current * Child->consume();
-        });
+    float Boost = DEFAULT_BOOST_SCORE;
+    for (const auto &Child : Children)
+      Boost *= Child->consume();
+    return Boost;
   }
 
   size_t estimateSize() const override {
@@ -140,10 +139,10 @@ public:
 
   /// Returns true if all children are exhausted.
   bool reachedEnd() const override {
-    return std::all_of(begin(Children), end(Children),
-                       [](const std::unique_ptr<Iterator> &Child) {
-                         return Child->reachedEnd();
-                       });
+    for (const auto &Child : Children)
+      if (!Child->reachedEnd())
+        return false;
+    return true;
   }
 
   /// Moves each child pointing to the smallest DocID to the next item.
@@ -181,21 +180,18 @@ public:
   float consume() override {
     assert(!reachedEnd() && "OR iterator can't consume() at the end.");
     const DocID ID = peek();
-    return std::accumulate(
-        begin(Children), end(Children), DEFAULT_BOOST_SCORE,
-        [&](float Boost, const std::unique_ptr<Iterator> &Child) {
-          return (!Child->reachedEnd() && Child->peek() == ID)
-                     ? std::max(Boost, Child->consume())
-                     : Boost;
-        });
+    float Boost = DEFAULT_BOOST_SCORE;
+    for (const auto &Child : Children)
+      if (!Child->reachedEnd() && Child->peek() == ID)
+        Boost = std::max(Boost, Child->consume());
+    return Boost;
   }
 
   size_t estimateSize() const override {
-    return std::accumulate(
-        begin(Children), end(Children), Children.front()->estimateSize(),
-        [&](size_t Current, const std::unique_ptr<Iterator> &Child) {
-          return std::max(Current, Child->estimateSize());
-        });
+    size_t Size = 0;
+    for (const auto &Child : Children)
+      Size = std::max(Size, Child->estimateSize());
+    return Size;
   }
 
 private:

Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.h?rev=342974&r1=342973&r2=342974&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.h Tue Sep 25 06:58:48 2018
@@ -6,25 +6,26 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//
-// Symbol index queries consist of specific requirements for the requested
-// symbol, such as high fuzzy matching score, scope, type etc. The lists of all
-// symbols matching some criteria (e.g. belonging to "clang::clangd::" scope)
-// are expressed in a form of Search Tokens which are stored in the inverted
-// index. Inverted index maps these tokens to the posting lists - sorted (by
-// symbol quality) sequences of symbol IDs matching the token, e.g. scope token
-// "clangd::clangd::" is mapped to the list of IDs of all symbols which are
-// declared in this namespace. Search queries are build from a set of
-// requirements which can be combined with each other forming the query trees.
-// The leafs of such trees are posting lists, and the nodes are operations on
-// these posting lists, e.g. intersection or union. Efficient processing of
-// these multi-level queries is handled by Iterators. Iterators advance through
-// all leaf posting lists producing the result of search query, which preserves
-// the sorted order of IDs. Having the resulting IDs sorted is important,
-// because it allows receiving a certain number of the most valuable items (e.g.
-// symbols with highest quality which was the sorting key in the first place)
-// without processing all items with requested properties (this might not be
-// computationally effective if search request is not very restrictive).
+///
+/// \file
+/// Symbol index queries consist of specific requirements for the requested
+/// symbol, such as high fuzzy matching score, scope, type etc. The lists of all
+/// symbols matching some criteria (e.g. belonging to "clang::clangd::" scope)
+/// are expressed in a form of Search Tokens which are stored in the inverted
+/// index. Inverted index maps these tokens to the posting lists - sorted (by
+/// symbol quality) sequences of symbol IDs matching the token, e.g. scope token
+/// "clangd::clangd::" is mapped to the list of IDs of all symbols which are
+/// declared in this namespace. Search queries are build from a set of
+/// requirements which can be combined with each other forming the query trees.
+/// The leafs of such trees are posting lists, and the nodes are operations on
+/// these posting lists, e.g. intersection or union. Efficient processing of
+/// these multi-level queries is handled by Iterators. Iterators advance through
+/// all leaf posting lists producing the result of search query, which preserves
+/// the sorted order of IDs. Having the resulting IDs sorted is important,
+/// because it allows receiving a certain number of the most valuable items
+/// (e.g. symbols with highest quality which was the sorting key in the first
+/// place) without processing all items with requested properties (this might
+/// not be computationally effective if search request is not very restrictive).
 //
 //===----------------------------------------------------------------------===//
 

Modified: clang-tools-extra/trunk/clangd/index/dex/Token.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Token.h?rev=342974&r1=342973&r2=342974&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Token.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Token.h Tue Sep 25 06:58:48 2018
@@ -6,17 +6,18 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//
-// Token objects represent a characteristic of a symbol, which can be used to
-// perform efficient search. Tokens are keys for inverted index which are mapped
-// to the corresponding posting lists.
-//
-// The symbol std::cout might have the tokens:
-// * Scope "std::"
-// * Trigram "cou"
-// * Trigram "out"
-// * Type "std::ostream"
-//
+///
+/// \file
+/// Token objects represent a characteristic of a symbol, which can be used to
+/// perform efficient search. Tokens are keys for inverted index which are
+/// mapped to the corresponding posting lists.
+///
+/// The symbol std::cout might have the tokens:
+/// * Scope "std::"
+/// * Trigram "cou"
+/// * Trigram "out"
+/// * Type "std::ostream"
+///
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DEX_TOKEN_H

Modified: clang-tools-extra/trunk/clangd/index/dex/Trigram.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Trigram.h?rev=342974&r1=342973&r2=342974&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/index/dex/Trigram.h (original)
+++ clang-tools-extra/trunk/clangd/index/dex/Trigram.h Tue Sep 25 06:58:48 2018
@@ -6,18 +6,19 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//
-// Trigrams are attributes of the symbol unqualified name used to effectively
-// extract symbols which can be fuzzy-matched given user query from the inverted
-// index. To match query with the extracted set of trigrams Q, the set of
-// generated trigrams T for identifier (unqualified symbol name) should contain
-// all items of Q, i.e. Q ⊆ T.
-//
-// Trigram sets extracted from unqualified name and from query are different:
-// the set of query trigrams only contains consecutive sequences of three
-// characters (which is only a subset of all trigrams generated for an
-// identifier).
-//
+///
+/// \file
+/// Trigrams are attributes of the symbol unqualified name used to effectively
+/// extract symbols which can be fuzzy-matched given user query from the
+/// inverted index. To match query with the extracted set of trigrams Q, the set
+/// of generated trigrams T for identifier (unqualified symbol name) should
+/// contain all items of Q, i.e. Q ⊆ T.
+///
+/// Trigram sets extracted from unqualified name and from query are different:
+/// the set of query trigrams only contains consecutive sequences of three
+/// characters (which is only a subset of all trigrams generated for an
+/// identifier).
+///
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_DEX_TRIGRAM_H




More information about the cfe-commits mailing list