Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/restore Don't allocate struct entry one by one; it just...
details: https://anonhg.NetBSD.org/src/rev/b24f26eb3e1d
branches: trunk
changeset: 539483:b24f26eb3e1d
user: enami <enami%NetBSD.org@localhost>
date: Mon Nov 18 04:28:03 2002 +0000
description:
Don't allocate struct entry one by one; it just wastes memory.
diffstat:
sbin/restore/main.c | 6 ++++--
sbin/restore/restore.h | 3 ++-
sbin/restore/symtab.c | 21 +++++++++++++--------
3 files changed, 19 insertions(+), 11 deletions(-)
diffs (96 lines):
diff -r 149c273fe8c5 -r b24f26eb3e1d sbin/restore/main.c
--- a/sbin/restore/main.c Mon Nov 18 03:17:24 2002 +0000
+++ b/sbin/restore/main.c Mon Nov 18 04:28:03 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.21 2001/02/19 22:56:22 cgd Exp $ */
+/* $NetBSD: main.c,v 1.22 2002/11/18 04:28:03 enami Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/4/95";
#else
-__RCSID("$NetBSD: main.c,v 1.21 2001/02/19 22:56:22 cgd Exp $");
+__RCSID("$NetBSD: main.c,v 1.22 2002/11/18 04:28:03 enami Exp $");
#endif
#endif /* not lint */
@@ -77,6 +77,7 @@
ino_t maxino;
time_t dumptime;
time_t dumpdate;
+size_t pagesize;
FILE *terminal;
char *tmpdir;
@@ -177,6 +178,7 @@
if (signal(SIGTERM, onintr) == SIG_IGN)
(void) signal(SIGTERM, SIG_IGN);
setlinebuf(stderr);
+ pagesize = sysconf(_SC_PAGESIZE);
atexit(cleanup);
diff -r 149c273fe8c5 -r b24f26eb3e1d sbin/restore/restore.h
--- a/sbin/restore/restore.h Mon Nov 18 03:17:24 2002 +0000
+++ b/sbin/restore/restore.h Mon Nov 18 04:28:03 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: restore.h,v 1.11 2001/08/24 10:24:46 wiz Exp $ */
+/* $NetBSD: restore.h,v 1.12 2002/11/18 04:28:03 enami Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -64,6 +64,7 @@
extern time_t dumptime; /* time that this dump begins */
extern time_t dumpdate; /* time that this dump was made */
extern char command; /* opration being performed */
+extern size_t pagesize; /* system page size */
extern FILE *terminal; /* file descriptor for the terminal input */
extern char *tmpdir; /* where to store temporary files */
extern int oldinofmt; /* reading tape with old format inodes */
diff -r 149c273fe8c5 -r b24f26eb3e1d sbin/restore/symtab.c
--- a/sbin/restore/symtab.c Mon Nov 18 03:17:24 2002 +0000
+++ b/sbin/restore/symtab.c Mon Nov 18 04:28:03 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: symtab.c,v 1.15 2002/08/12 02:40:20 itojun Exp $ */
+/* $NetBSD: symtab.c,v 1.16 2002/11/18 04:28:03 enami Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)symtab.c 8.3 (Berkeley) 4/28/95";
#else
-__RCSID("$NetBSD: symtab.c,v 1.15 2002/08/12 02:40:20 itojun Exp $");
+__RCSID("$NetBSD: symtab.c,v 1.16 2002/11/18 04:28:03 enami Exp $");
#endif
#endif /* not lint */
@@ -233,15 +233,20 @@
{
struct entry *np, *ep;
- if (freelist != NULL) {
- np = freelist;
- freelist = np->e_next;
- memset(np, 0, (long)sizeof(struct entry));
- } else {
- np = (struct entry *)calloc(1, sizeof(struct entry));
+ if (freelist == NULL) {
+ np = malloc(pagesize);
if (np == NULL)
panic("no memory to extend symbol table\n");
+ for (ep = (struct entry *)((char *)np + pagesize) - 1;
+ np <= ep; np++) {
+ np->e_next = freelist;
+ freelist = np;
+ }
}
+ np = freelist;
+ freelist = np->e_next;
+ memset(np, 0, (long)sizeof(struct entry));
+
np->e_type = type & ~LINK;
ep = lookupparent(name);
if (ep == NULL) {
Home |
Main Index |
Thread Index |
Old Index