summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-28 06:36:46 +0000
committerChris Lattner <sabre@nondot.org>2009-12-28 06:36:46 +0000
commit9e0005f44511e300ef3e34c8c98829bdd91d6ad0 (patch)
tree2bec6d85fecf343a8ee9ac6f330620487b0a59c0 /clang/lib
parent394f589e73224b0b07c7b92da7991d79a2f49e97 (diff)
downloadbcm5719-llvm-9e0005f44511e300ef3e34c8c98829bdd91d6ad0.tar.gz
bcm5719-llvm-9e0005f44511e300ef3e34c8c98829bdd91d6ad0.zip
use best-fit instead of first-fit when reusing a MacroArgs object,
this speeds up Eonly on the testcase in PR5888 from 30.5s to 0.85s llvm-svn: 92203
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Lex/MacroArgs.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/clang/lib/Lex/MacroArgs.cpp b/clang/lib/Lex/MacroArgs.cpp
index 4883898e3cd..2f1a34c8329 100644
--- a/clang/lib/Lex/MacroArgs.cpp
+++ b/clang/lib/Lex/MacroArgs.cpp
@@ -24,25 +24,34 @@ MacroArgs *MacroArgs::create(const MacroInfo *MI,
Preprocessor &PP) {
assert(MI->isFunctionLike() &&
"Can't have args for an object-like macro!");
- MacroArgs *Result = 0;
+ MacroArgs **ResultEnt = 0;
+ unsigned ClosestMatch = ~0U;
// See if we have an entry with a big enough argument list to reuse on the
// free list. If so, reuse it.
for (MacroArgs **Entry = &PP.MacroArgCache; *Entry;
Entry = &(*Entry)->ArgCache)
- if ((*Entry)->NumUnexpArgTokens >= NumToks) {
- Result = *Entry;
- // Unlink this node from the preprocessors singly linked list.
- *Entry = Result->ArgCache;
- break;
+ if ((*Entry)->NumUnexpArgTokens >= NumToks &&
+ (*Entry)->NumUnexpArgTokens < ClosestMatch) {
+ ResultEnt = Entry;
+
+ // If we have an exact match, use it.
+ if ((*Entry)->NumUnexpArgTokens == NumToks)
+ break;
+ // Otherwise, use the best fit.
+ ClosestMatch = (*Entry)->NumUnexpArgTokens;
}
- if (Result == 0) {
+ MacroArgs *Result;
+ if (ResultEnt == 0) {
// Allocate memory for a MacroArgs object with the lexer tokens at the end.
Result = (MacroArgs*)malloc(sizeof(MacroArgs) + NumToks*sizeof(Token));
// Construct the MacroArgs object.
new (Result) MacroArgs(NumToks, VarargsElided);
} else {
+ Result = *ResultEnt;
+ // Unlink this node from the preprocessors singly linked list.
+ *ResultEnt = Result->ArgCache;
Result->NumUnexpArgTokens = NumToks;
Result->VarargsElided = VarargsElided;
}
OpenPOWER on IntegriCloud