From 3b5bbaefcb771df6ff63f1040fd452bbde824703 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 25 Oct 2007 15:19:16 +0000 Subject: [PATCH] =?UTF-8?q?optimise=20(struct=20padding,=20function?= =?UTF-8?q?=E2=86=92macro,=20etc.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- edit.c | 26 +++++++++++--------------- expr.c | 9 +++------ main.c | 12 ++---------- misc.c | 8 ++++---- sh.h | 22 +++++++++++----------- tree.c | 26 +++++++++++++------------- 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/edit.c b/edit.c index 47877d7..870e26d 100644 --- a/edit.c +++ b/edit.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.115 2007/10/14 13:43:41 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.116 2007/10/25 15:19:15 tg Exp $"); /* tty driver characters we are interested in */ typedef struct { @@ -26,8 +26,7 @@ X_chars edchars; #define XCF_COMMAND_FILE (XCF_COMMAND|XCF_FILE) static int x_getc(void); -static void x_flush(void); -static void x_putc(int); +static void x_putcf(int); static bool x_mode(bool); static int x_do_comment(char *, int, int *); static void x_print_expansions(int, char *const *, int); @@ -43,6 +42,9 @@ static void x_init_prompt(void); static int x_vi(char *, size_t); #endif +#define x_flush() shf_flush(shl_out) +#define x_putc(c) shf_putc((c), shl_out) + #ifdef TIOCGWINSZ static void chkwinsz(void); #endif @@ -141,13 +143,7 @@ x_getc(void) } static void -x_flush(void) -{ - shf_flush(shl_out); -} - -static void -x_putc(int c) +x_putcf(int c) { shf_putc(c, shl_out); } @@ -443,8 +439,8 @@ x_command_glob(int flags, const char *str, int slen, char ***wordsp) return nwords; } -#define IS_WORDC(c) !( ctype(c, C_LEX1) || (c) == '\'' || (c) == '"' || \ - (c) == '`' || (c) == '=' || (c) == ':' ) +#define IS_WORDC(c) (!ctype(c, C_LEX1) && (c) != '\'' && (c) != '"' && \ + (c) != '`' && (c) != '=' && (c) != ':') static int x_locate_word(const char *buf, int buflen, int pos, int *startp, @@ -2988,7 +2984,7 @@ x_e_putc3(const char **cp) width = utf_widthadj(*cp, (const char **)&cp2); while (*cp < cp2) - x_putc(*(*cp)++); + x_putcf(*(*cp)++); } else { (*cp)++; x_putc(c); @@ -5193,7 +5189,7 @@ ed_mov_opt(int col, char *wb) pprompt(prompt, prompt_trunc); cur_col = pwidth; while (cur_col++ < col) - x_putc(*wb++); + x_putcf(*wb++); } else { while (cur_col-- > col) x_putc('\b'); @@ -5201,7 +5197,7 @@ ed_mov_opt(int col, char *wb) } else { wb = &wb[cur_col - pwidth]; while (cur_col++ < col) - x_putc(*wb++); + x_putcf(*wb++); } cur_col = col; } diff --git a/expr.c b/expr.c index 79f4980..b2d92db 100644 --- a/expr.c +++ b/expr.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.12 2007/07/22 14:01:48 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.13 2007/10/25 15:19:16 tg Exp $"); /* The order of these enums is constrained by the order of opinfo[] */ enum token { @@ -111,13 +111,10 @@ struct expr_state { const char *tokp; /* lexical position */ enum token tok; /* token from token() */ int noassign; /* don't do assigns (for ?:,&&,||) */ - bool arith; /* true if evaluating an $(()) - * expression - */ struct tbl *val; /* value from token() */ struct tbl *evaling; /* variable that is being recursively - * expanded (EXPRINEVAL flag set) - */ + * expanded (EXPRINEVAL flag set) */ + bool arith; /* evaluating an $(()) expression? */ }; enum error_type { diff --git a/main.c b/main.c index 626b530..b6f62e1 100644 --- a/main.c +++ b/main.c @@ -13,7 +13,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.87 2007/08/19 22:06:26 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.88 2007/10/25 15:19:16 tg Exp $"); extern char **environ; @@ -713,11 +713,9 @@ reclaim(void) static void remove_temps(struct temp *tp) { - for (; tp != NULL; tp = tp->next) - if (tp->pid == procpid) { + if (tp->pid == procpid) unlink(tp->name); - } } /* Initialise tty_fd. Used for saving/reseting tty modes upon @@ -1268,12 +1266,6 @@ ktenter(struct table *tp, const char *n, unsigned int h) return p; } -void -ktdelete(struct tbl *p) -{ - p->flag = 0; -} - void ktwalk(struct tstate *ts, struct table *tp) { diff --git a/misc.c b/misc.c index 997f400..6ccc981 100644 --- a/misc.c +++ b/misc.c @@ -6,7 +6,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.66 2007/09/09 18:06:41 tg Exp $\t" +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.67 2007/10/25 15:19:16 tg Exp $\t" MKSH_SH_H_ID); #undef USE_CHVT @@ -481,11 +481,11 @@ getn(const char *s, int *ai) int bi_getn(const char *as, int *ai) { - int rv = getn(as, ai); + int rv; - if (!rv) + if (!(rv = getn(as, ai))) bi_errorf("%s: bad number", as); - return rv; + return (rv); } /* -------- gmatch.c -------- */ diff --git a/sh.h b/sh.h index f2b3fc2..c3b4eb2 100644 --- a/sh.h +++ b/sh.h @@ -8,7 +8,7 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.181 2007/10/25 14:26:53 tg Exp $" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.182 2007/10/25 15:19:16 tg Exp $" #define MKSH_VERSION "R32 2007/10/25" #if HAVE_SYS_PARAM_H @@ -333,14 +333,14 @@ EXTERN Area aperm; /* permanent object space */ * parsing & execution environment */ EXTERN struct env { - short type; /* environment type - see below */ - short flags; /* EF_* */ Area area; /* temporary allocation area */ struct block *loc; /* local variables and functions */ short *savefd; /* original redirected fds */ struct env *oenv; /* link to previous environment */ - sigjmp_buf jbuf; /* long jump back to env creator */ struct temp *temps; /* temp files */ + sigjmp_buf jbuf; /* long jump back to env creator */ + short type; /* environment type - see below */ + short flags; /* EF_* */ } *e; /* struct env.type values */ @@ -686,8 +686,8 @@ extern struct shf shf_iob[]; struct table { Area *areap; /* area to allocate entries */ - short size, nfree; /* hash size (always 2^^n), free entries */ struct tbl **tbls; /* hashed table items */ + short size, nfree; /* hash size (always 2^^n), free entries */ }; struct tbl { /* table item */ @@ -857,11 +857,6 @@ EXTERN int current_lineno; /* LINENO value */ * Description of a command or an operation on commands. */ struct op { - short type; /* operation type, see below */ - union { /* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */ - short evalflags; /* TCOM: arg expansion eval() flags */ - short ksh_func; /* TFUNC: function x (vs x()) */ - } u; const char **args; /* arguments to a command */ char **vars; /* variable assignments */ struct ioword **ioact; /* IO actions (eg, < > >>) */ @@ -872,6 +867,11 @@ struct op { * time hook for TCOM. */ int lineno; /* TCOM/TFUNC: LINENO for this */ + short type; /* operation type, see below */ + union { /* WARNING: newtp(), tcopy() use evalflags = 0 to clear union */ + short evalflags; /* TCOM: arg expansion eval() flags */ + short ksh_func; /* TFUNC: function x (vs x()) */ + } u; }; /* Tree.type values */ @@ -1394,7 +1394,7 @@ unsigned int hash(const char *); void ktinit(struct table *, Area *, int); struct tbl *ktsearch(struct table *, const char *, unsigned int); struct tbl *ktenter(struct table *, const char *, unsigned int); -void ktdelete(struct tbl *); +#define ktdelete(p) do { p->flag = 0 } while (0) void ktwalk(struct tstate *, struct table *); struct tbl *ktnext(struct tstate *); struct tbl **ktsort(struct table *); diff --git a/tree.c b/tree.c index 9817eaf..0ad26e7 100644 --- a/tree.c +++ b/tree.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.11 2007/07/06 01:53:36 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.12 2007/10/25 15:19:16 tg Exp $"); #define INDENT 4 @@ -336,29 +336,29 @@ tputS(char *wp, struct shf *shf) int fptreef(struct shf *shf, int indent, const char *fmt, ...) { - va_list va; + va_list va; - va_start(va, fmt); + va_start(va, fmt); - vfptreef(shf, indent, fmt, va); - va_end(va); - return 0; + vfptreef(shf, indent, fmt, va); + va_end(va); + return (0); } /* VARARGS */ char * snptreef(char *s, int n, const char *fmt, ...) { - va_list va; - struct shf shf; + va_list va; + struct shf shf; - shf_sopen(s, n, SHF_WR | (s ? 0 : SHF_DYNAMIC), &shf); + shf_sopen(s, n, SHF_WR | (s ? 0 : SHF_DYNAMIC), &shf); - va_start(va, fmt); - vfptreef(&shf, 0, fmt, va); - va_end(va); + va_start(va, fmt); + vfptreef(&shf, 0, fmt, va); + va_end(va); - return shf_sclose(&shf); /* null terminates */ + return (shf_sclose(&shf)); /* null terminates */ } static void