On 12/06/2013 13:10, Bram Moolenaar wrote:
Patch 7.3.1171
Problem: Check for digits and ascii letters can be faster.
Solution: Use a trick with one comparison. (Dominique Pelle)
Files: src/macros.h
*** ../vim-7.3.1170/src/macros.h 2013-06-08 18:19:40.000000000 +0200
--- src/macros.h 2013-06-12 14:03:00.000000000 +0200
***************
*** 109,123 ****
#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
/* 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')
/* macro version of chartab().
* Only works with values 0-255!
--- 109,122 ----
#else
# define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c))
# define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c))
! # define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26)
! # define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26)
#endif
/* 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. */
! #define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10)
/* macro version of chartab().
* Only works with values 0-255!
*** ../vim-7.3.1170/src/version.c 2013-06-12 13:37:36.000000000 +0200
--- src/version.c 2013-06-12 14:09:00.000000000 +0200
***************
*** 730,731 ****
--- 730,733 ----
{ /* Add new patch number below this line */
+ /**/
+ 1171,
/**/
Unfortunately the functions that need speeding up are isalpha() and
isalnum(). Without those VIM is no faster, even with the above patch.
The following patch solves the performance issue by applying the same
technique for isalpha() and isalnum(). It also needs the change to
modifier_len() since this is called a lot from has_loop_cmd():
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
@@ -107,8 +107,8 @@
# define ASCII_ISLOWER(c) islower(c)
# define ASCII_ISUPPER(c) isupper(c)
#else
-# define ASCII_ISALPHA(c) ((c) < 0x7f && isalpha(c))
-# define ASCII_ISALNUM(c) ((c) < 0x7f && isalnum(c))
+# define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c))
+# define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c))
# define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26)
# define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26)
#endif
Mike
--
Yoghurt the Great, Yoghurt the All Powerful? No just plain yoghurt.
--
--
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.