Hi Bram and Vim developers,

2015/4/22(Wed) 2:08:56 UTC+9 Bram Moolenaar:
> Hirohito Higashi wrote:
> 
> > Hi Bram and Vimmers,
> > 
> > I wrote a patch for built-in indentation improve speed.
> > 
> > Summary:
> > cin_is_cpp_baseclass() search 'C++ baseclass' backward every time in 
> > for-loop in misc1.c:7745~8710.
> > When no C++ baseclass, look up each time the first line.
> > This is not good.
> >  
> > I modified to cache the cin_is_cpp_baseclass()'s result.
> > 
> > 
> > Time Measurement:
> > $ vim -N -u NONE -c "set cino+=i2 cin" test.c
> > :so disptime.vim
> > 
> > Base vim version: 7.4.707
> > non-patched: 11.487525 sec
> > patched:      0.225243 sec (Improve speed x50 !!!)
> > 
> > Please check and include this.
>  
> Thanks, a very nice improvement.
> 
> Instead of using a new structure lfpos_T, I would prefer to use the
> existing lpos_T and a separate "found" flag.

Sure, I update a patch.
Please check this.

--
Best regards,
Hirohito Higashi (a.k.a. h_east)

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff -r 3790fb70e04c src/misc1.c
--- a/src/misc1.c	Tue Apr 21 19:10:49 2015 +0200
+++ b/src/misc1.c	Wed Apr 22 11:36:55 2015 +0900
@@ -5409,7 +5409,7 @@
 static int	cin_is_if_for_while_before_offset __ARGS((char_u *line, int *poffset));
 static int	cin_iswhileofdo_end __ARGS((int terminated));
 static int	cin_isbreak __ARGS((char_u *));
-static int	cin_is_cpp_baseclass __ARGS((colnr_T *col));
+static int	cin_is_cpp_baseclass __ARGS((int *found, lpos_T *pos));
 static int	get_baseclass_amount __ARGS((int col));
 static int	cin_ends_in __ARGS((char_u *, char_u *, char_u *));
 static int	cin_starts_with __ARGS((char_u *s, char *word));
@@ -6372,15 +6372,19 @@
  * This is a lot of guessing.  Watch out for "cond ? func() : foo".
  */
     static int
-cin_is_cpp_baseclass(col)
-    colnr_T	*col;	    /* return: column to align with */
+cin_is_cpp_baseclass(found, pos)
+    int		*found;	    /* previous find result. input and output */
+    lpos_T	*pos;	    /* previous find position. input and output */
 {
     char_u	*s;
     int		class_or_struct, lookfor_ctor_init, cpp_base_class;
     linenr_T	lnum = curwin->w_cursor.lnum;
     char_u	*line = ml_get_curline();
 
-    *col = 0;
+    if (pos->lnum <= lnum)
+	return *found;	/* Use a cache */
+
+    pos->col = 0;
 
     s = skipwhite(line);
     if (*s == '#')		/* skip #define FOO x ? (x) : x */
@@ -6424,6 +6428,7 @@
 	--lnum;
     }
 
+    pos->lnum = lnum;
     line = ml_get(lnum);
     s = cin_skipcomment(line);
     for (;;)
@@ -6456,7 +6461,7 @@
 		 * cpp-base-class-declaration or constructor-initialization */
 		cpp_base_class = TRUE;
 		lookfor_ctor_init = class_or_struct = FALSE;
-		*col = 0;
+		pos->col = 0;
 		s = cin_skipcomment(s + 1);
 	    }
 	    else
@@ -6497,24 +6502,27 @@
 		class_or_struct = FALSE;
 		lookfor_ctor_init = FALSE;
 	    }
-	    else if (*col == 0)
+	    else if (pos->col == 0)
 	    {
 		/* it can't be a constructor-initialization any more */
 		lookfor_ctor_init = FALSE;
 
 		/* the first statement starts here: lineup with this one... */
 		if (cpp_base_class)
-		    *col = (colnr_T)(s - line);
+		    pos->col = (colnr_T)(s - line);
 	    }
 
 	    /* When the line ends in a comma don't align with it. */
 	    if (lnum == curwin->w_cursor.lnum && *s == ',' && cin_nocode(s + 1))
-		*col = 0;
+		pos->col = 0;
 
 	    s = cin_skipcomment(s + 1);
 	}
     }
 
+    *found = cpp_base_class;
+    if (cpp_base_class)
+	pos->lnum = lnum;
     return cpp_base_class;
 }
 
@@ -7047,7 +7055,7 @@
 #define LOOKFOR_CPP_BASECLASS	9
 #define LOOKFOR_ENUM_OR_INIT	10
 #define LOOKFOR_JS_KEY		11
-#define LOOKFOR_COMMA	12
+#define LOOKFOR_COMMA		12
 
     int		whilelevel;
     linenr_T	lnum;
@@ -7059,6 +7067,11 @@
     int		original_line_islabel;
     int		added_to_amount = 0;
     int		js_cur_has_key = 0;
+    /* Find result cache for cpp_baseclass */
+    struct {
+	int found;
+	lpos_T lpos;
+    } cache_cpp_baseclass = { FALSE, { MAXLNUM, 0 } };
 
     /* make a copy, value is changed below */
     int		ind_continuation = curbuf->b_ind_continuation;
@@ -8089,7 +8102,8 @@
 		n = FALSE;
 		if (lookfor != LOOKFOR_TERM && curbuf->b_ind_cpp_baseclass > 0)
 		{
-		    n = cin_is_cpp_baseclass(&col);
+		    n = cin_is_cpp_baseclass(&cache_cpp_baseclass.found,
+						&cache_cpp_baseclass.lpos);
 		    l = ml_get_curline();
 		}
 		if (n)
@@ -8110,7 +8124,8 @@
 		    }
 		    else
 								     /* XXX */
-			amount = get_baseclass_amount(col);
+			amount = get_baseclass_amount(
+						cache_cpp_baseclass.lpos.col);
 		    break;
 		}
 		else if (lookfor == LOOKFOR_CPP_BASECLASS)
@@ -8780,13 +8795,14 @@
 		n = FALSE;
 		if (curbuf->b_ind_cpp_baseclass != 0 && theline[0] != '{')
 		{
-		    n = cin_is_cpp_baseclass(&col);
+		    n = cin_is_cpp_baseclass(&cache_cpp_baseclass.found,
+						&cache_cpp_baseclass.lpos);
 		    l = ml_get_curline();
 		}
 		if (n)
 		{
 								     /* XXX */
-		    amount = get_baseclass_amount(col);
+		    amount = get_baseclass_amount(cache_cpp_baseclass.lpos.col);
 		    break;
 		}
 

Raspunde prin e-mail lui