[hackers] [scc] [cc2] Add locals at the end of the list || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 14 Apr 2016 08:25:55 +0200 (CEST)

commit 162d7ec1030b696b09740e1dc5494f1d644a53d6
Author: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
AuthorDate: Thu Apr 14 08:24:31 2016 +0200
Commit: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
CommitDate: Thu Apr 14 08:24:31 2016 +0200

    [cc2] Add locals at the end of the list
    
    We were inserting always in the head of the list, and it means
    that the list had inverse order. This patch modifies it and
    now the symbols are inserted at the end of the list.

diff --git a/cc2/symbol.c b/cc2/symbol.c
index f3bed3b..0a54ae1 100644
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
_AT_@ -11,7 +11,7 @@
 
 #define NR_SYMHASH 64
 
-static Symbol *symtab[NR_SYMHASH];
+static Symbol *symtab[NR_SYMHASH], *curlocal;
 static Symbol *locals;
 static int infunction;
 
_AT_@ -40,7 +40,7 @@ popctx(void)
                 symtab[sym->id & NR_SYMHASH-1] = sym->h_next;
                 freesym(sym);
         }
- locals = NULL;
+ curlocal = locals = NULL;
 }
 
 Symbol *
_AT_@ -59,11 +59,12 @@ getsym(unsigned id)
         if (!sym) {
                 sym = xcalloc(1, sizeof(*sym));
                 sym->id = id;
- if (!infunction) {
- sym->next = NULL;
- } else {
- sym->next = locals;
- locals = sym;
+ if (infunction) {
+ if (!locals)
+ locals = sym;
+ if (curlocal)
+ curlocal->next = sym;
+ curlocal = sym;
                 }
                 sym->h_next = *htab;
                 *htab = sym;
Received on Thu Apr 14 2016 - 08:25:55 CEST

This archive was generated by hypermail 2.3.0 : Thu Apr 14 2016 - 08:36:16 CEST