Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make make(1): use shorter field names in Lst and Lst...



details:   https://anonhg.NetBSD.org/src/rev/c1c055346ae8
branches:  trunk
changeset: 937556:c1c055346ae8
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Aug 21 06:38:29 2020 +0000

description:
make(1): use shorter field names in Lst and LstNode

In a doubly linked list, it is commonly known that the 'prev' and 'next'
fields of the nodes are pointers to other nodes, therefore this does not
need to be repeated in the variable name.

diffstat:

 usr.bin/make/lst.c |  209 ++++++++++++++++++++++++++--------------------------
 1 files changed, 103 insertions(+), 106 deletions(-)

diffs (truncated from 490 to 300 lines):

diff -r 182f8d033b90 -r c1c055346ae8 usr.bin/make/lst.c
--- a/usr.bin/make/lst.c        Fri Aug 21 06:37:30 2020 +0000
+++ b/usr.bin/make/lst.c        Fri Aug 21 06:38:29 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lst.c,v 1.14 2020/08/21 06:28:38 rillig Exp $ */
+/* $NetBSD: lst.c,v 1.15 2020/08/21 06:38:29 rillig Exp $ */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -38,17 +38,17 @@
 #include "make_malloc.h"
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: lst.c,v 1.14 2020/08/21 06:28:38 rillig Exp $";
+static char rcsid[] = "$NetBSD: lst.c,v 1.15 2020/08/21 06:38:29 rillig Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: lst.c,v 1.14 2020/08/21 06:28:38 rillig Exp $");
+__RCSID("$NetBSD: lst.c,v 1.15 2020/08/21 06:38:29 rillig Exp $");
 #endif /* not lint */
 #endif
 
 struct ListNode {
-    struct ListNode *prevPtr;  /* previous element in list */
-    struct ListNode *nextPtr;  /* next in list */
+    struct ListNode *prev;     /* previous element in list */
+    struct ListNode *next;     /* next in list */
     uint8_t useCount;          /* Count of functions using the node.
                                 * node may not be deleted until count
                                 * goes to 0 */
@@ -61,16 +61,16 @@
 } Where;
 
 struct List {
-    LstNode firstPtr;          /* first node in list */
-    LstNode lastPtr;           /* last node in list */
+    LstNode first;             /* first node in list */
+    LstNode last;              /* last node in list */
 /*
  * fields for sequential access
  */
-    Where atEnd;               /* Where in the list the last access was */
+    Where lastAccess;          /* Where in the list the last access was */
     Boolean isOpen;            /* true if list has been Lst_Open'ed */
-    LstNode curPtr;            /* current node, if open. NULL if
+    LstNode curr;              /* current node, if open. NULL if
                                 * *just* opened */
-    LstNode prevPtr;           /* Previous node, if open. Used by
+    LstNode prev;              /* Previous node, if open. Used by
                                 * Lst_Remove */
 };
 
@@ -92,8 +92,8 @@
 LstNodeNew(void *datum)
 {
     LstNode ln = bmake_malloc(sizeof *ln);
-    /* prevPtr will be initialized by the calling code. */
-    /* nextPtr will be initialized by the calling code. */
+    /* prev will be initialized by the calling code. */
+    /* next will be initialized by the calling code. */
     ln->useCount = 0;
     ln->deleted = FALSE;
     ln->datum = datum;
@@ -104,7 +104,7 @@
 static Boolean
 LstIsEmpty(Lst l)
 {
-    return l->firstPtr == NULL;
+    return l->first == NULL;
 }
 
 /* Create and initialize a new, empty list. */
@@ -113,10 +113,10 @@
 {
     Lst nList = bmake_malloc(sizeof *nList);
 
-    nList->firstPtr = NULL;
-    nList->lastPtr = NULL;
+    nList->first = NULL;
+    nList->last = NULL;
     nList->isOpen = FALSE;
-    nList->atEnd = Unknown;
+    nList->lastAccess = Unknown;
 
     return nList;
 }
@@ -141,7 +141,7 @@
        return NULL;
     }
 
-    ln = list->firstPtr;
+    ln = list->first;
     while (ln != NULL) {
        if (copyProc != NULL) {
            if (Lst_AtEnd(nl, copyProc(ln->datum)) == FAILURE) {
@@ -151,7 +151,7 @@
            return NULL;
        }
 
-       ln = ln->nextPtr;
+       ln = ln->next;
     }
 
     return nl;
@@ -169,22 +169,22 @@
        return;
 
     /* To ease scanning */
-    if (list->lastPtr != NULL)
-       list->lastPtr->nextPtr = NULL;
+    if (list->last != NULL)
+       list->last->next = NULL;
     else {
        free(list);
        return;
     }
 
     if (freeProc) {
-       for (ln = list->firstPtr; ln != NULL; ln = tln) {
-           tln = ln->nextPtr;
+       for (ln = list->first; ln != NULL; ln = tln) {
+           tln = ln->next;
            freeProc(ln->datum);
            free(ln);
        }
     } else {
-       for (ln = list->firstPtr; ln != NULL; ln = tln) {
-           tln = ln->nextPtr;
+       for (ln = list->first; ln != NULL; ln = tln) {
+           tln = ln->next;
            free(ln);
        }
     }
@@ -220,19 +220,19 @@
     nLNode = LstNodeNew(d);
 
     if (ln == NULL) {
-       nLNode->prevPtr = nLNode->nextPtr = NULL;
-       list->firstPtr = list->lastPtr = nLNode;
+       nLNode->prev = nLNode->next = NULL;
+       list->first = list->last = nLNode;
     } else {
-       nLNode->prevPtr = lNode->prevPtr;
-       nLNode->nextPtr = lNode;
+       nLNode->prev = lNode->prev;
+       nLNode->next = lNode;
 
-       if (nLNode->prevPtr != NULL) {
-           nLNode->prevPtr->nextPtr = nLNode;
+       if (nLNode->prev != NULL) {
+           nLNode->prev->next = nLNode;
        }
-       lNode->prevPtr = nLNode;
+       lNode->prev = nLNode;
 
-       if (lNode == list->firstPtr) {
-           list->firstPtr = nLNode;
+       if (lNode == list->first) {
+           list->first = nLNode;
        }
     }
 
@@ -263,19 +263,19 @@
     nLNode = LstNodeNew(d);
 
     if (lNode == NULL) {
-       nLNode->nextPtr = nLNode->prevPtr = NULL;
-       list->firstPtr = list->lastPtr = nLNode;
+       nLNode->next = nLNode->prev = NULL;
+       list->first = list->last = nLNode;
     } else {
-       nLNode->prevPtr = lNode;
-       nLNode->nextPtr = lNode->nextPtr;
+       nLNode->prev = lNode;
+       nLNode->next = lNode->next;
 
-       lNode->nextPtr = nLNode;
-       if (nLNode->nextPtr != NULL) {
-           nLNode->nextPtr->prevPtr = nLNode;
+       lNode->next = nLNode;
+       if (nLNode->next != NULL) {
+           nLNode->next->prev = nLNode;
        }
 
-       if (lNode == list->lastPtr) {
-           list->lastPtr = nLNode;
+       if (lNode == list->last) {
+           list->last = nLNode;
        }
     }
 
@@ -316,34 +316,34 @@
     /*
      * unlink it from the list
      */
-    if (lNode->nextPtr != NULL) {
-       lNode->nextPtr->prevPtr = lNode->prevPtr;
+    if (lNode->next != NULL) {
+       lNode->next->prev = lNode->prev;
     }
-    if (lNode->prevPtr != NULL) {
-       lNode->prevPtr->nextPtr = lNode->nextPtr;
+    if (lNode->prev != NULL) {
+       lNode->prev->next = lNode->next;
     }
 
     /*
-     * if either the firstPtr or lastPtr of the list point to this node,
+     * if either the first or last of the list point to this node,
      * adjust them accordingly
      */
-    if (list->firstPtr == lNode) {
-       list->firstPtr = lNode->nextPtr;
+    if (list->first == lNode) {
+       list->first = lNode->next;
     }
-    if (list->lastPtr == lNode) {
-       list->lastPtr = lNode->prevPtr;
+    if (list->last == lNode) {
+       list->last = lNode->prev;
     }
 
     /*
      * Sequential access stuff. If the node we're removing is the current
      * node in the list, reset the current node to the previous one. If the
-     * previous one was non-existent (prevPtr == NULL), we set the
+     * previous one was non-existent (prev == NULL), we set the
      * end to be Unknown, since it is.
      */
-    if (list->isOpen && (list->curPtr == lNode)) {
-       list->curPtr = list->prevPtr;
-       if (list->curPtr == NULL) {
-           list->atEnd = Unknown;
+    if (list->isOpen && (list->curr == lNode)) {
+       list->curr = list->prev;
+       if (list->curr == NULL) {
+           list->lastAccess = Unknown;
        }
     }
 
@@ -378,7 +378,7 @@
     if (!LstValid(l) || LstIsEmpty(l)) {
        return NULL;
     } else {
-       return l->firstPtr;
+       return l->first;
     }
 }
 
@@ -390,7 +390,7 @@
     if (!LstValid(l) || LstIsEmpty(l)) {
        return NULL;
     } else {
-       return l->lastPtr;
+       return l->last;
     }
 }
 
@@ -401,7 +401,7 @@
     if (ln == NULL) {
        return NULL;
     } else {
-       return ln->nextPtr;
+       return ln->next;
     }
 }
 
@@ -412,7 +412,7 @@
     if (ln == NULL) {
        return NULL;
     } else {
-       return ln->prevPtr;
+       return ln->prev;
     }
 }
 
@@ -465,7 +465,7 @@
     do {
        if ((*cProc)(tln->datum, d) == 0)
            return tln;
-       tln = tln->nextPtr;
+       tln = tln->next;
     } while (tln != ln && tln != NULL);
 
     return NULL;
@@ -481,7 +481,7 @@
     if (list == NULL) {
        return NULL;
     }
-    lNode = list->firstPtr;
+    lNode = list->first;
     if (lNode == NULL) {
        return NULL;
     }
@@ -490,8 +490,8 @@
        if (lNode->datum == d) {
            return lNode;
        }
-       lNode = lNode->nextPtr;



Home | Main Index | Thread Index | Old Index