Hi,
Never leave a developer in possession of a profiler ...
So with my setup, nerdtree takes a while to start in large directory of
files, such as VIM's src directory. On Windows the profiler shows a
large amount of time is being spent in the CRT's isalnum(), isalpha()
and islower() internals, coping with locale handling.
Working backwards shows the calls are actually from the ASCII_IS...()
macros in macros.h and mainly coming from get_name_len(),
has_loop_cmd(), find_command(), etc - so from VIML processing. There is
also a call in modifier_len() that AFAICT only has to handle ASCII as well.
Since these macros enforce ASCII character range there is no need to hit
locale handling. The simplest solution is to use a lookup table with a
bit mask for the classifications needed. I have thrown in handling for
VIM_ISDIGIT as well.
After the patch, starting nerdtree in VIM's src is ~35% faster (1.7s vs
2.6s) and the CRT's locale handling functions no longer appear in the
profile (and I warmed the file cache to remove disk reading from the
times). In general this should help speed up longer running VIML scripts.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3120,7 +3120,7 @@ modifier_len(cmd)
for (j = 0; p[j] != NUL; ++j)
if (p[j] != cmdmods[i].name[j])
break;
- if (!isalpha(p[j]) && j >= cmdmods[i].minlen
+ if (!ASCII_ISALPHA(p[j]) && j >= cmdmods[i].minlen
&& (p == cmd ||
cmdmods[i].has_count))
return j + (int)(p - cmd);
}
diff --git a/src/macros.h b/src/macros.h
--- a/src/macros.h
+++ b/src/macros.h
@@ -106,18 +106,26 @@
# define ASCII_ISALNUM(c) isalnum(c)
# define ASCII_ISLOWER(c) islower(c)
# define ASCII_ISUPPER(c) isupper(c)
+# define VIM_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
#else
-# define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c))
-# define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c))
-# define ASCII_ISLOWER(c) ((c) < 0x7f && islower(c))
-# define ASCII_ISUPPER(c) ((c) < 0x7f && isupper(c))
-#endif
-
+# define V_ALPHA (0x01)
+# define V_ALNUM (0x02)
+# define V_LOWER (0x04)
+# define V_UPPER (0x08)
+# define V_DIGIT (0x10)
+extern
+char_u ascii_table[128];
+# define ASCII_ISALPHA(c) ((c) < 0x7f && ascii_table[(c)] & V_ALPHA)
+# define ASCII_ISALNUM(c) ((c) < 0x7f && ascii_table[(c)] & V_ALNUM)
+# define ASCII_ISLOWER(c) ((c) < 0x7f && ascii_table[(c)] & V_LOWER)
+# define ASCII_ISUPPER(c) ((c) < 0x7f && ascii_table[(c)] & V_UPPER)
/* Use our own isdigit() replacement, because on MS-Windows isdigit()
returns
* non-zero for superscript 1. Also avoids that isdigit() crashes for
numbers
* below 0 and above 255. For complicated arguments and in/decrement use
* vim_isdigit() instead. */
-#define VIM_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
+# define VIM_ISDIGIT(c) ((c) < 0x7f && ascii_table[(c)] & V_DIGIT)
+#endif
+
/* macro version of chartab().
* Only works with values 0-255!
diff --git a/src/misc2.c b/src/misc2.c
--- a/src/misc2.c
+++ b/src/misc2.c
@@ -12,6 +12,140 @@
*/
#include "vim.h"
+/*
+ * Bit table for ASCII character classification macros in macros.h.
+ */
+char_u ascii_table[128] = {
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* */ 0,
+ /* ! */ 0,
+ /* " */ 0,
+ /* # */ 0,
+ /* $ */ 0,
+ /* % */ 0,
+ /* & */ 0,
+ /* ' */ 0,
+ /* ( */ 0,
+ /* ) */ 0,
+ /* * */ 0,
+ /* + */ 0,
+ /* , */ 0,
+ /* - */ 0,
+ /* . */ 0,
+ /* / */ 0,
+ /* 0 */ V_ALNUM|V_DIGIT,
+ /* 1 */ V_ALNUM|V_DIGIT,
+ /* 2 */ V_ALNUM|V_DIGIT,
+ /* 3 */ V_ALNUM|V_DIGIT,
+ /* 4 */ V_ALNUM|V_DIGIT,
+ /* 5 */ V_ALNUM|V_DIGIT,
+ /* 6 */ V_ALNUM|V_DIGIT,
+ /* 7 */ V_ALNUM|V_DIGIT,
+ /* 8 */ V_ALNUM|V_DIGIT,
+ /* 9 */ V_ALNUM|V_DIGIT,
+ /* : */ 0,
+ /* ; */ 0,
+ /* < */ 0,
+ /* = */ 0,
+ /* > */ 0,
+ /* ? */ 0,
+ /* @ */ 0,
+ /* A */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* B */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* C */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* D */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* E */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* F */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* G */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* H */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* I */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* J */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* K */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* L */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* M */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* N */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* O */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* P */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* Q */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* R */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* S */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* T */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* U */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* V */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* W */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* X */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* Y */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* Z */ V_UPPER|V_ALNUM|V_ALPHA,
+ /* [ */ 0,
+ /* \ */ 0,
+ /* ] */ 0,
+ /* ^ */ 0,
+ /* _ */ 0,
+ /* ` */ 0,
+ /* a */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* b */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* c */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* d */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* e */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* f */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* g */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* h */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* i */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* j */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* k */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* l */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* m */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* n */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* o */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* p */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* q */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* r */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* s */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* t */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* u */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* v */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* w */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* x */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* y */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* z */ V_LOWER|V_ALNUM|V_ALPHA,
+ /* { */ 0,
+ /* | */ 0,
+ /* } */ 0,
+ /* ~ */ 0,
+ /* */ 0
+};
+
static char_u *username = NULL; /* cached result of
mch_get_user_name() */
static char_u *ff_expand_buffer = NULL; /* used for expanding
filenames */
TTFN
Mike
--
For every action, there is an equal but opposite critical analysis.
--
--
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/groups/opt_out.