[clang-tools-extra] c4830af - [clangd] Use unique_function for config handlers (#203008)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 14 22:59:01 PDT 2026
Author: David Zbarsky
Date: 2026-07-15T01:58:57-04:00
New Revision: c4830afdbbc7b16a52a05d6a5b56e6c3fc14fb98
URL: https://github.com/llvm/llvm-project/commit/c4830afdbbc7b16a52a05d6a5b56e6c3fc14fb98
DIFF: https://github.com/llvm/llvm-project/commit/c4830afdbbc7b16a52a05d6a5b56e6c3fc14fb98.diff
LOG: [clangd] Use unique_function for config handlers (#203008)
`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.
Added:
Modified:
clang-tools-extra/clangd/ConfigYAML.cpp
Removed:
################################################################################
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);
}
More information about the cfe-commits
mailing list