ilya-biryukov added inline comments.

================
Comment at: clangd/ClangdUnit.cpp:276
+class DeclarationLocationsFinder : public index::IndexDataConsumer {
+  std::unique_ptr<std::vector<Location>> DeclarationLocations;
+  const SourceLocation &SearchedLocation;
----------------
malaperle-ericsson wrote:
> malaperle-ericsson wrote:
> > ilya-biryukov wrote:
> > > Why do we need to use `unique_ptr<vector<Location>>` here and in other 
> > > places instead of `vector<Location>`? 
> > It was to implement "takeLocations". Calling it claims ownship of the 
> > vector. Did you have something else in mind when you suggested to implement 
> > takeLocations with a std::move? Disclaimer: this c++11 stuff is all new to 
> > me so I wouldn't be surprised if I'm doing it in a terrible way.
> I guess I can make takeLocations return a vector&& and the other places will 
> return a normal vector RVO will take care of not making copies?
Just return `std::vector` and `std::move` the original field. It will have the 
same behaviour (i.e. no copies of the vector data, ownership transferred to the 
caller) without extra heap allocs:


```
  std::vector<Location> takeLocations() {
    // .... Do postprocessing here, i.e. sort+unique+erase
    return std::move(DeclarationLocations);
  }
// ...
private:
  std::vector<Location> DeclarationLocations;
```


https://reviews.llvm.org/D34269



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to