On Thursday 17 July 2008 19:48, L. Gabriel Somlo wrote:
> On Mon, Jul 14, 2008 at 11:21:39PM +0200, Denys Vlasenko wrote:
> > Cool eh? ;) Can you do the same?
>
> Done, options are now taken care of.
>
> > Lately there is a trend to have all new applets to be like this:
> >
> > # size mdev.o
> > text data bss dec hex filename
> > 2176 0 0 2176 880 mdev.o
> >
> > zero zero :)
>
> Allright, so I rewrote the whole prg_cache_* function set to
> essentially use a linked list instead of a hash (slower, but doesn't
> require global data beyond one single pointer for the list head, and
> we don't care because we don't expect there to be *that* many
> processes where linear lookup times would become noticeable).
Oh, sorry, I probably had to be more clear.
You do not need to rework your algorithm to _totally_
eliminate globals. Sometimes it makes it much uglier
and/or bigger and/or slower.
You need to just minimize usage of globals. IOW: use them
when it is _noticeably_ more difficult to not do so.
And then, when you have just a few globals, use "G trick".
See, for example, crontab.c:
struct globals {
unsigned LogLevel; /* = 8; */
const char *LogFile;
const char *CDir; /* = CRONTABS; */
CronFile *FileBase;
#if SETENV_LEAKS
char *env_var_user;
char *env_var_home;
#endif
};
#define G (*(struct globals*)&bb_common_bufsiz1)
#define LogLevel (G.LogLevel )
#define LogFile (G.LogFile )
#define CDir (G.CDir )
#define FileBase (G.FileBase )
#define env_var_user (G.env_var_user )
#define env_var_home (G.env_var_home )
#define INIT_G() do { \
LogLevel = 8; \
CDir = CRONTABS; \
} while (0)
...
int crond_main(...)
{
unsigned opt;
INIT_G();
...
> So, what do you think about this latest version of the patch ?
Apart from the above:
Option bit masks now look ok.
+#define PROGNAME_WIDTH 20
+
+#define PROGNAME_WIDTHs PROGNAME_WIDTH1(PROGNAME_WIDTH)
+#define PROGNAME_WIDTH1(s) PROGNAME_WIDTH2(s)
+#define PROGNAME_WIDTH2(s) #s
Well. Why not just #define PROGNAME_WIDTHs "20" so than reader
doesn't get confused?
+#define PRG_SOCKET_PFX "socket:["
+#define PRG_SOCKET_PFXl (strlen(PRG_SOCKET_PFX))
+#define PRG_SOCKET_PFX2 "[0000]:"
+#define PRG_SOCKET_PFX2l (strlen(PRG_SOCKET_PFX2))
My faith in gcc optimizing strlen is not so high.
Can you use sizeof("str")-1 instead?
(and something wrong with indentation).
+static long extract_socket_inode(const char lname[]) {
+
Should be
static long extract_socket_inode(const char *lname)
{
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox