llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-tools-extra

Author: David Zbarsky (dzbarsky)

<details>
<summary>Changes</summary>

`ConfigYAML.cpp`'s `DictParser` owns its callbacks for one parse and never 
copies them, so this replaces `std::function` with move-only 
`llvm::unique_function` and removes the unused copy machinery for each lambda.

In a matched Release AArch64 build, `ConfigYAML.cpp.o` shrank by 94,560 bytes, 
stripped clangd shrank by 16,848 bytes, unstripped clangd shrank by 82,512 
bytes, and dyld fixups fell by 336.

Validated with the 16 `ParseYAML` unit tests and `clangd --check`; 12 paired 
runs of 100,000 parses improved mean user CPU time by 3.46% (95% CI: 1.31% to 
5.61%).

Work towards #<!-- -->202616

AI tool disclosure: Co-authored with OpenAI Codex.


---
Full diff: https://github.com/llvm/llvm-project/pull/203008.diff


1 Files Affected:

- (modified) clang-tools-extra/clangd/ConfigYAML.cpp (+10-4) 


``````````diff
diff --git a/clang-tools-extra/clangd/ConfigYAML.cpp 
b/clang-tools-extra/clangd/ConfigYAML.cpp
index 7b6993620fb8c..940c7b8bd2de1 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ b/clang-tools-extra/clangd/ConfigYAML.cpp
@@ -7,6 +7,7 @@
 
//===----------------------------------------------------------------------===//
 #include "ConfigFragment.h"
 #include "support/Logger.h"
+#include "llvm/ADT/FunctionExtras.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
@@ -334,8 +335,11 @@ class Parser {
   // We don't use YamlIO as we want to control over unknown keys.
   class DictParser {
     llvm::StringRef Description;
-    std::vector<std::pair<llvm::StringRef, std::function<void(Node &)>>> Keys;
-    std::function<bool(Located<std::string>, Node &)> UnknownHandler;
+    std::vector<
+        std::pair<llvm::StringRef, llvm::unique_function<void(Node &) const>>>
+        Keys;
+    llvm::unique_function<bool(Located<std::string>, Node &) const>
+        UnknownHandler;
     Parser *Outer;
 
   public:
@@ -345,7 +349,8 @@ class Parser {
     // Parse is called when Key is encountered, and passed the associated 
value.
     // It should emit diagnostics if the value is invalid (e.g. wrong type).
     // If Key is seen twice, Parse runs only once and an error is reported.
-    void handle(llvm::StringLiteral Key, std::function<void(Node &)> Parse) {
+    void handle(llvm::StringLiteral Key,
+                llvm::unique_function<void(Node &) const> Parse) {
       for (const auto &Entry : Keys) {
         (void)Entry;
         assert(Entry.first != Key && "duplicate key handler");
@@ -357,7 +362,8 @@ class Parser {
     // If this is unset or the Handler returns true, a warning is emitted for
     // the unknown key.
     void
-    unrecognized(std::function<bool(Located<std::string>, Node &)> Handler) {
+    unrecognized(llvm::unique_function<bool(Located<std::string>, Node &) 
const>
+                     Handler) {
       UnknownHandler = std::move(Handler);
     }
 

``````````

</details>


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

Reply via email to