Replace index_in_[sub]str_array with index_in_[sub]strings,

which scans thru "abc\0def\0123\0\0" type strings. Saves 250 bytes.

   text    data     bss     dec     hex filename
 781266    1328   11844  794438   c1f46 busybox_old
 781010    1328   11844  794182   c1e46 busybox_unstripped
This commit is contained in:
Denis Vlasenko
2007-07-24 15:54:42 +00:00
parent bcb66ec22e
commit 990d0f63ee
43 changed files with 352 additions and 340 deletions

View File

@@ -51,7 +51,7 @@ static ssize_t full_write_or_warn(int fd, const void *buf, size_t len,
}
static bool write_and_stats(int fd, const void *buf, size_t len, size_t obs,
const char * const filename)
const char *filename)
{
ssize_t n = full_write_or_warn(fd, buf, len, filename);
if (n < 0)
@@ -78,13 +78,12 @@ int dd_main(int argc, char **argv)
TRUNC_FLAG = 1 << 2,
TWOBUFS_FLAG = 1 << 3,
};
static const char * const keywords[] = {
"bs=", "count=", "seek=", "skip=", "if=", "of=",
static const char keywords[] =
"bs=\0""count=\0""seek=\0""skip=\0""if=\0""of=\0"
#if ENABLE_FEATURE_DD_IBS_OBS
"ibs=", "obs=", "conv=", "notrunc", "sync", "noerror",
"ibs=\0""obs=\0""conv=\0""notrunc\0""sync\0""noerror\0"
#endif
NULL
};
;
enum {
OP_bs = 1,
OP_count,
@@ -134,7 +133,7 @@ int dd_main(int argc, char **argv)
bb_show_usage();
key_len = key - arg + 1;
key = xstrndup(arg, key_len);
what = index_in_str_array(keywords, key) + 1;
what = index_in_strings(keywords, key) + 1;
if (ENABLE_FEATURE_CLEAN_UP)
free(key);
if (what == 0)
@@ -153,13 +152,13 @@ int dd_main(int argc, char **argv)
if (what == OP_conv) {
while (1) {
/* find ',', replace them with nil so we can use arg for
* index_in_str_array without copying.
* index_in_strings() without copying.
* We rely on arg being non-null, else strchr would fault.
*/
key = strchr(arg, ',');
if (key)
*key = '\0';
what = index_in_str_array(keywords, arg) + 1;
what = index_in_strings(keywords, arg) + 1;
if (what < OP_conv_notrunc)
bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv");
if (what == OP_conv_notrunc)
@@ -298,15 +297,15 @@ int dd_main(int argc, char **argv)
G.out_part++;
}
if (close(ifd) < 0) {
die_infile:
die_infile:
bb_perror_msg_and_die("%s", infile);
}
if (close(ofd) < 0) {
die_outfile:
die_outfile:
bb_perror_msg_and_die("%s", outfile);
}
out_status:
out_status:
dd_output_status(0);
return EXIT_SUCCESS;

View File

@@ -38,7 +38,7 @@ extern char **environ;
static const char env_longopts[] =
"ignore-environment\0" No_argument "i"
"unset\0" Required_argument "u"
"\0";
;
#endif
int env_main(int argc, char** argv);

View File

@@ -277,14 +277,13 @@ static VALUE *eval7(void)
static VALUE *eval6(void)
{
static const char * const keywords[] = {
"quote", "length", "match", "index", "substr", NULL
};
static const char keywords[] =
"quote\0""length\0""match\0""index\0""substr\0";
VALUE *r, *i1, *i2;
VALUE *l = l; /* silence gcc */
VALUE *v = v; /* silence gcc */
int key = *G.args ? index_in_str_array(keywords, *G.args) + 1 : 0;
int key = *G.args ? index_in_strings(keywords, *G.args) + 1 : 0;
if (key == 0) /* not a keyword */
return eval7();

View File

@@ -28,7 +28,7 @@ static const char install_longopts[] =
"preserve_context\0" No_argument "\xff"
"preserve-context\0" No_argument "\xff"
#endif
"\0";
;
#endif

View File

@@ -122,7 +122,7 @@ static smallint show_color;
* equivalent */
static const char ls_color_opt[] =
"color\0" Optional_argument "\xff" /* no short equivalent */
"\0";
;
#else
enum { show_color = 0 };
#endif

View File

@@ -31,7 +31,7 @@ static const char mkdir_longopts[] =
#if ENABLE_SELINUX
"context\0" Required_argument "Z"
#endif
"\0";
;
#endif
int mkdir_main(int argc, char **argv);

View File

@@ -24,7 +24,7 @@
static const char mv_longopts[] =
"interactive\0" No_argument "i"
"force\0" No_argument "f"
"\0";
;
#endif
#define OPT_FILEUTILS_FORCE 1

View File

@@ -1242,7 +1242,7 @@ int od_main(int argc, char **argv)
"strings\0" Optional_argument "S"
"width\0" Optional_argument "w"
"traditional\0" No_argument "\xff"
"\0";
;
#endif
char *str_A, *str_N, *str_j, *str_S;
char *str_w = NULL;

View File

@@ -562,18 +562,16 @@ enum {
static int find_param(const char * const name)
{
static const char * const params[] = {
"line", /* 1 */
"rows", /* 2 */
"cols", /* 3 */
"columns", /* 4 */
"size", /* 5 */
"ispeed"+1, /* 6 */
"ispeed",
"ospeed",
NULL
};
int i = index_in_str_array(params, name) + 1;
static const char params[] =
"line\0" /* 1 */
"rows\0" /* 2 */
"cols\0" /* 3 */
"columns\0" /* 4 */
"size\0" /* 5 */
"speed\0" /* 6 */
"ispeed\0"
"ospeed\0";
int i = index_in_strings(params, name) + 1;
if (i == 0)
return 0;
if (i != 5 && i != 6)

View File

@@ -51,11 +51,10 @@ static unsigned int expand(const char *arg, char *buffer)
char *buffer_start = buffer;
unsigned i; /* XXX: FIXME: use unsigned char? */
unsigned char ac;
#define CLO ":]"
static const char * const classes[] = {
"alpha"CLO, "alnum"CLO, "digit"CLO, "lower"CLO, "upper"CLO, "space"CLO,
"blank"CLO, "punct"CLO, "cntrl"CLO, NULL
};
#define CLO ":]\0"
static const char classes[] =
"alpha"CLO "alnum"CLO "digit"CLO "lower"CLO "upper"CLO "space"CLO
"blank"CLO "punct"CLO "cntrl"CLO;
#define CLASS_invalid 0 /* we increment the retval */
#define CLASS_alpha 1
#define CLASS_alnum 2
@@ -90,7 +89,7 @@ static unsigned int expand(const char *arg, char *buffer)
smalluint j;
{ /* not really pretty.. */
char *tmp = xstrndup(arg, 7); // warning: xdigit needs 8, not 7
j = index_in_str_array(classes, tmp) + 1;
j = index_in_strings(classes, tmp) + 1;
free(tmp);
}
if (j == CLASS_alnum || j == CLASS_digit) {