================
@@ -64,5 +64,34 @@ RefSlab RefSlab::Builder::build() && {
   return RefSlab(std::move(Result), std::move(Arena), Entries.size());
 }
 
+void RefSlab::BuilderExpectUnique::insert(const SymbolID &ID, const Ref &S) {
+  Entry E = {ID, S};
+  E.Reference.Location.FileURI = UniqueStrings.save(S.Location.FileURI).data();
+  Entries.emplace_back(std::move(E));
+}
+
+RefSlab RefSlab::BuilderExpectUnique::build() && {
+  std::vector<std::pair<SymbolID, llvm::ArrayRef<Ref>>> Result;
+  // We'll reuse the arena, as it only has unique strings and we need them all.
+  // We need to group refs by symbol and form contiguous arrays on the arena.
+  // Group by SymbolID.
+  llvm::sort(Entries);
+  assert(std::adjacent_find(Entries.cbegin(), Entries.cend()) ==
+             Entries.cend() &&
+         "Entries are expected to be unique");
+  std::vector<Ref> Refs;
+  // Loop over symbols, copying refs for each onto the arena.
+  for (auto I = Entries.begin(), End = Entries.end(); I != End;) {
+    SymbolID Sym = I->Symbol;
+    Refs.clear();
+    do {
+      Refs.push_back(I->Reference);
+      ++I;
+    } while (I != End && I->Symbol == Sym);
+    Result.emplace_back(Sym, llvm::ArrayRef<Ref>(Refs).copy(Arena));
----------------
HighCommander4 wrote:

`Builder::build()` has a 
[sort](https://searchfox.org/llvm/rev/84ce7b1f1d2997d1880f9b24ee6e6a75d4045e0a/clang-tools-extra/clangd/index/Ref.cpp#61)
 step here with the comment `// By file, affects xrefs display order`.

_This_ sort does compare the contents of the file URI strings rather than their 
pointers.

I think we need to keep this sort step in `BuilderExpectUnique` to preserve 
behaviour.

https://github.com/llvm/llvm-project/pull/156185
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to