diff mbox series

[committed] d: Use Array::find to get index of element

Message ID 20210406174618.1594147-1-ibuclaw@gdcproject.org
State New
Headers show
Series [committed] d: Use Array::find to get index of element | expand

Commit Message

Iain Buclaw April 6, 2021, 5:46 p.m. UTC
Hi,

This patch refactors some code in the code generator to use the
Array::find method to get the index of an element, instead of looping
over the array ourselves.

Bootstrapped and regression tested on x86_64-linux-gnu/-m32/-mx32 and
committed to mainline.

Regards,
Iain.

---
gcc/d/ChangeLog:

	* d-codegen.cc (build_frame_type): Use Array::find to get index of
	element.
---
 gcc/d/d-codegen.cc | 28 ++++++++++------------------
 1 file changed, 10 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc
index 608abcd94f5..5fa1acd9240 100644
--- a/gcc/d/d-codegen.cc
+++ b/gcc/d/d-codegen.cc
@@ -2507,15 +2507,11 @@  build_frame_type (tree ffi, FuncDeclaration *fd)
 	    {
 	      VarDeclaration *v = (*fd->parameters)[i];
 	      /* Remove if already in closureVars so can push to front.  */
-	      for (size_t j = i; j < fd->closureVars.length; j++)
-		{
-		  Dsymbol *s = fd->closureVars[j];
-		  if (s == v)
-		    {
-		      fd->closureVars.remove (j);
-		      break;
-		    }
-		}
+	      size_t j = fd->closureVars.find (v);
+
+	      if (j < fd->closureVars.length)
+		fd->closureVars.remove (j);
+
 	      fd->closureVars.insert (i, v);
 	    }
 	}
@@ -2523,15 +2519,11 @@  build_frame_type (tree ffi, FuncDeclaration *fd)
       /* Also add hidden `this' to outer context.  */
       if (fd->vthis)
 	{
-	  for (size_t i = 0; i < fd->closureVars.length; i++)
-	    {
-	      Dsymbol *s = fd->closureVars[i];
-	      if (s == fd->vthis)
-		{
-		  fd->closureVars.remove (i);
-		  break;
-		}
-	    }
+	  size_t i = fd->closureVars.find (fd->vthis);
+
+	  if (i < fd->closureVars.length)
+	    fd->closureVars.remove (i);
+
 	  fd->closureVars.insert (0, fd->vthis);
 	}
     }