[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.
This commit is contained in:
parent
74822b4ee0
commit
c4830afdbb
1 changed files with 10 additions and 4 deletions
|
|
@ -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 @@ private:
|
|||
// 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 @@ private:
|
|||
// 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 @@ private:
|
|||
// 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue