Patchwork [C++] Small clean up to binding_to_template_parms_of_scope_p

login
register
mail settings
Submitter Paolo Carlini
Date Jan. 21, 2012, 1:07 a.m.
Message ID <4F1A0FB8.5000706@oracle.com>
Download mbox | patch
Permalink /patch/137131/
State New
Headers show

Comments

Paolo Carlini - Jan. 21, 2012, 1:07 a.m.
Hi,

I was looking a bit into PR51398 and noticed this opportunity. It seems 
also not a bad idea performance-wise, given in particular that the 
function is called in a loop. But maybe it's more suited for Stage 1, 
just let me know. Tested x86_64-linux.

Thanks,
Paolo.

//////////////////////
2012-01-21  Paolo Carlini  <paolo.carlini@oracle.com>

	* name-lookup.c (binding_to_template_parms_of_scope_p): Clean up.
Jason Merrill - Jan. 21, 2012, 1:33 a.m.
Yep, OK for stage 1.

Jason

Patch

Index: name-lookup.c
===================================================================
--- name-lookup.c	(revision 183359)
+++ name-lookup.c	(working copy)
@@ -4467,20 +4467,17 @@  binding_to_template_parms_of_scope_p (cxx_binding
 				      cp_binding_level *scope)
 {
   tree binding_value;
+  tree tinfo;
 
-  if (!binding || !scope)
+  if (!binding || !scope || !scope->this_entity)
     return false;
 
   binding_value = binding->value ?  binding->value : binding->type;
+  tinfo = get_template_info (scope->this_entity);
 
-  return (scope
-	  && scope->this_entity
-	  && get_template_info (scope->this_entity)
-	  && PRIMARY_TEMPLATE_P (TI_TEMPLATE
-				 (get_template_info (scope->this_entity)))
-	  && parameter_of_template_p (binding_value,
-				      TI_TEMPLATE (get_template_info \
-						    (scope->this_entity))));
+  return (tinfo
+	  && PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo))
+	  && parameter_of_template_p (binding_value, TI_TEMPLATE (tinfo)));
 }
 
 /* Return the innermost non-namespace binding for NAME from a scope