This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Trivial cleanup

I was looking at the vec class to figure out the best way to do some things and realized we have a "last" member function. Using foo.last() is clearer than foo[foo.length() - 1]

On a related note, our current standards require a space between a function name and the open paren for its argument list. However, it leads to fugly code in some cases. Assume foo is an vec instance and we want to look at something in the last vector element. Our current standards would imply something like this:

foo.last ()->bar

Which is how the current patch formats that code. However, I typically see this more often in C++ codebases as


But then, what if we just want the last element without peeking deeper inside it?

foo.last ()?



Do we want to make any changes in our style guidelines to handle this better?

Anyway, bootstrapped & regression tested on x86_64-unknown-linux-gnu. Installed onto the trunk.

        * tree-ssa-threadedge.c (thread_across_edge): Use foo.last () rather
        than foo[foo.length () - 1] to access last member in a vec.
        * tree-ssa-threadupdate.c (register_jump_thread): Similarly.

diff --git a/gcc/tree-ssa-threadedge.c b/gcc/tree-ssa-threadedge.c
index 47db280..2ca56342 100644
--- a/gcc/tree-ssa-threadedge.c
+++ b/gcc/tree-ssa-threadedge.c
@@ -947,8 +947,7 @@ thread_across_edge (gimple dummy_cond,
 	  remove_temporary_equivalences (stack);
-	  propagate_threaded_block_debug_into (path[path.length () - 1]->dest,
-					       e->dest);
+	  propagate_threaded_block_debug_into (path.last ()->dest, e->dest);
 	  register_jump_thread (path, false);
 	  path.release ();
@@ -987,7 +986,7 @@ thread_across_edge (gimple dummy_cond,
 	path.safe_push (taken_edge);
 	found = false;
 	if ((e->flags & EDGE_DFS_BACK) == 0
-	    || ! cond_arg_set_in_bb (path[path.length () - 1], e->dest))
+	    || ! cond_arg_set_in_bb (path.last (), e->dest))
 	  found = thread_around_empty_blocks (taken_edge,
@@ -999,7 +998,7 @@ thread_across_edge (gimple dummy_cond,
 	   record the jump threading opportunity.  */
 	if (found)
-	    propagate_threaded_block_debug_into (path[path.length () - 1]->dest,
+	    propagate_threaded_block_debug_into (path.last ()->dest,
 	    register_jump_thread (path, true);
diff --git a/gcc/tree-ssa-threadupdate.c b/gcc/tree-ssa-threadupdate.c
index 4131128..fd5234c 100644
--- a/gcc/tree-ssa-threadupdate.c
+++ b/gcc/tree-ssa-threadupdate.c
@@ -1401,7 +1401,7 @@ register_jump_thread (vec<edge> path, bool through_joiner)
   if (!through_joiner)
     e3 = NULL;
-    e3 = path[path.length () - 1];
+    e3 = path.last ();
   /* This can occur if we're jumping to a constant address or
      or something similar.  Just get out now.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]