File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -264,7 +264,15 @@ impl ExpnId {
264264 HygieneData :: with ( |data| data. expn_data ( self ) . clone ( ) )
265265 }
266266
267+ #[ inline]
267268 pub fn is_descendant_of ( self , ancestor : ExpnId ) -> bool {
269+ // a few "fast path" cases to avoid locking HygieneData
270+ if ancestor == ExpnId :: root ( ) || ancestor == self {
271+ return true ;
272+ }
273+ if ancestor. krate != self . krate {
274+ return false ;
275+ }
268276 HygieneData :: with ( |data| data. is_descendant_of ( self , ancestor) )
269277 }
270278
@@ -376,13 +384,22 @@ impl HygieneData {
376384 }
377385
378386 fn is_descendant_of ( & self , mut expn_id : ExpnId , ancestor : ExpnId ) -> bool {
379- while expn_id != ancestor {
387+ // a couple "fast path" cases to avoid traversing parents in the loop below
388+ if ancestor == ExpnId :: root ( ) {
389+ return true ;
390+ }
391+ if expn_id. krate != ancestor. krate {
392+ return false ;
393+ }
394+ loop {
395+ if expn_id == ancestor {
396+ return true ;
397+ }
380398 if expn_id == ExpnId :: root ( ) {
381399 return false ;
382400 }
383401 expn_id = self . expn_data ( expn_id) . parent ;
384402 }
385- true
386403 }
387404
388405 fn normalize_to_macros_2_0 ( & self , ctxt : SyntaxContext ) -> SyntaxContext {
You can’t perform that action at this time.
0 commit comments