bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gawk: saving space in the NODE structure


From: Aharon Robbins
Subject: gawk: saving space in the NODE structure
Date: Thu, 10 Oct 2002 15:03:50 +0200

Greetings all.  I just spent some time looking over the gawk NODE
structure.  There isn't a lot of room for space savings in it, actually,
unless you're going to rewrite gawk from scratch.

However, the unofficial patch below gets gawk through my test suite
without crashing, and saves 8 bytes (out of 40 on the x86).  The more
adventurous among you might like to apply it and see if gawk starts core
dumping on anything. 20% savings isn't a bad start. :-)

I'm still thinking about arrays. Arrays use 3 NODEs per element:

        1 - link in the hash chain
        2 - holds string value of index
        3 - holds element value (string or number)

It's easy enough to move the string value stuff into the link in the hash
chain, saving 40 (okay, now 32) bytes, but only if you don't want to do
`for (x in foo)' loops.  Seeing as how most of you wouldn't want to give
that up, I'll continue to think. :-)

Arnold
------------------ cut here ----------------------------
*** ../gawk-3.1.1/awk.h Tue Apr 16 14:40:18 2002
--- awk.h       Thu Oct 10 15:02:27 2002
***************
*** 422,428 ****
                                char **param_list;
                        } x;
                        char *name;
!                       short number;
                        unsigned char reflags;
  #                             define  CASE    1
  #                             define  CONST   2
--- 416,422 ----
                                char **param_list;
                        } x;
                        char *name;
!                       long number;
                        unsigned char reflags;
  #                             define  CASE    1
  #                             define  CONST   2
***************
*** 474,485 ****
  #             define  FIELD   2048    /* this is a field */
  #             define  INTLSTR 4096    /* use localized version */
  #             define  UNINITIALIZED   8192    /* value used before set */
        char *vname;
  #ifndef NO_PROFILING
!       long exec_count;
  #endif
  } NODE;
  
  #define lnode sub.nodep.l.lptr
  #define nextp sub.nodep.l.lptr
  #define rnode sub.nodep.r.rptr
--- 468,484 ----
  #             define  FIELD   2048    /* this is a field */
  #             define  INTLSTR 4096    /* use localized version */
  #             define  UNINITIALIZED   8192    /* value used before set */
+       /*
        char *vname;
+       */
  #ifndef NO_PROFILING
!       /* long exec_count; */
  #endif
  } NODE;
  
+ #define exec_count sub.nodep.number
+ #define vname sub.nodep.name
+ 
  #define lnode sub.nodep.l.lptr
  #define nextp sub.nodep.l.lptr
  #define rnode sub.nodep.r.rptr
-- 
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd.     address@hidden
P.O. Box 354            Home Phone: +972  8 979-0381    Fax: +1 928 569 9018
Nof Ayalon              Cell Phone: +972 51  297-545
D.N. Shimshon 99785     ISRAEL




reply via email to

[Prev in Thread] Current Thread [Next in Thread]