summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa2016-08-14 23:30:29 +0200
committerDenys Vlasenko2016-08-14 23:30:29 +0200
commit7e6f9316a8bf3030da6c283e43aa0709d0cef259 (patch)
treeec5f4ba877f846b6fff854e2af8507d734edb98b
parent9e5820a86277818c2f83c11c2aa76d7f0a38283e (diff)
downloadbusybox-7e6f9316a8bf3030da6c283e43aa0709d0cef259.zip
busybox-7e6f9316a8bf3030da6c283e43aa0709d0cef259.tar.gz
lineedit: trivial codeshrink for vi-mode
Introduce and use BB_isalnum_or_underscore(). function old new delta BB_isalnum_or_underscore - 43 +43 vi_word_motion 162 150 -12 vi_end_motion 163 145 -18 vi_back_motion 198 179 -19 BB_isalnum 39 - -39 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/3 up/down: 43/-88) Total: -45 bytes Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--libbb/lineedit.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 3e62f46..3bfff00 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -81,7 +81,9 @@
# define CHAR_T wchar_t
static bool BB_isspace(CHAR_T c) { return ((unsigned)c < 256 && isspace(c)); }
# if ENABLE_FEATURE_EDITING_VI
-static bool BB_isalnum(CHAR_T c) { return ((unsigned)c < 256 && isalnum(c)); }
+static bool BB_isalnum_or_underscore(CHAR_T c) {
+ return ((unsigned)c < 256 && isalnum(c)) || c == '_';
+}
# endif
static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); }
# undef isspace
@@ -96,7 +98,11 @@ static bool BB_ispunct(CHAR_T c) { return ((unsigned)c < 256 && ispunct(c)); }
# define BB_NUL '\0'
# define CHAR_T char
# define BB_isspace(c) isspace(c)
-# define BB_isalnum(c) isalnum(c)
+# if ENABLE_FEATURE_EDITING_VI
+static bool BB_isalnum_or_underscore(CHAR_T c) {
+ return ((unsigned)c < 256 && isalnum(c)) || c == '_';
+}
+# endif
# define BB_ispunct(c) ispunct(c)
#endif
#if ENABLE_UNICODE_PRESERVE_BROKEN
@@ -1586,9 +1592,9 @@ vi_word_motion(int eat)
{
CHAR_T *command = command_ps;
- if (BB_isalnum(command[cursor]) || command[cursor] == '_') {
+ if (BB_isalnum_or_underscore(command[cursor])) {
while (cursor < command_len
- && (BB_isalnum(command[cursor+1]) || command[cursor+1] == '_')
+ && (BB_isalnum_or_underscore(command[cursor+1]))
) {
input_forward();
}
@@ -1630,9 +1636,9 @@ vi_end_motion(void)
input_forward();
if (cursor >= command_len-1)
return;
- if (BB_isalnum(command[cursor]) || command[cursor] == '_') {
+ if (BB_isalnum_or_underscore(command[cursor])) {
while (cursor < command_len-1
- && (BB_isalnum(command[cursor+1]) || command[cursor+1] == '_')
+ && (BB_isalnum_or_underscore(command[cursor+1]))
) {
input_forward();
}
@@ -1665,9 +1671,9 @@ vi_back_motion(void)
input_backward(1);
if (cursor <= 0)
return;
- if (BB_isalnum(command[cursor]) || command[cursor] == '_') {
+ if (BB_isalnum_or_underscore(command[cursor])) {
while (cursor > 0
- && (BB_isalnum(command[cursor-1]) || command[cursor-1] == '_')
+ && (BB_isalnum_or_underscore(command[cursor-1]))
) {
input_backward(1);
}