Skip to content

Commit 83f9088

Browse files
committed
Defer costly spelling expansion
1 parent 777d211 commit 83f9088

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/ir/var.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,6 @@ fn handle_function_macro(
141141
tokens: &[ClangToken],
142142
callbacks: &dyn crate::callbacks::ParseCallbacks,
143143
) -> Result<(), ParseError> {
144-
let mut spelled = tokens.iter().map(ClangToken::spelling);
145-
let boundary = spelled
146-
.clone() // clone the iterator to avoid consuming elements
147-
.position(|s| s == b")");
148-
149144
fn is_abutting(a: &ClangToken, b: &ClangToken) -> bool {
150145
unsafe {
151146
clang_sys::clang_equalLocations(
@@ -176,6 +171,13 @@ fn handle_function_macro(
176171
return Ok(());
177172
}
178173

174+
let is_closing_paren = |t: &ClangToken| {
175+
// Test cheap token kind before comparing exact spellings.
176+
t.kind == clang_sys::CXToken_Punctuation && t.spelling() == b")"
177+
};
178+
let boundary = tokens.iter().position(is_closing_paren);
179+
180+
let mut spelled = tokens.iter().map(ClangToken::spelling);
179181
// Add 1, to convert index to length.
180182
let left = spelled
181183
.by_ref()

0 commit comments

Comments
 (0)