Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/make Nuke Buf_{G, Ung}etByte{, s}(), since they aren't...
details: https://anonhg.NetBSD.org/src/rev/2f94dfc9294d
branches: trunk
changeset: 476374:2f94dfc9294d
user: mycroft <mycroft%NetBSD.org@localhost>
date: Wed Sep 15 04:16:31 1999 +0000
description:
Nuke Buf_{G,Ung}etByte{,s}(), since they aren't used, and make BufExpand do
power-of-2 allocation.
diffstat:
usr.bin/make/buf.c | 174 +---------------------------------------------------
usr.bin/make/buf.h | 6 +-
2 files changed, 6 insertions(+), 174 deletions(-)
diffs (235 lines):
diff -r d4796e568528 -r 2f94dfc9294d usr.bin/make/buf.c
--- a/usr.bin/make/buf.c Wed Sep 15 04:06:00 1999 +0000
+++ b/usr.bin/make/buf.c Wed Sep 15 04:16:31 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.c,v 1.11 1997/09/28 03:31:00 lukem Exp $ */
+/* $NetBSD: buf.c,v 1.12 1999/09/15 04:16:31 mycroft Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -39,14 +39,14 @@
*/
#ifdef MAKE_BOOTSTRAP
-static char rcsid[] = "$NetBSD: buf.c,v 1.11 1997/09/28 03:31:00 lukem Exp $";
+static char rcsid[] = "$NetBSD: buf.c,v 1.12 1999/09/15 04:16:31 mycroft Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)buf.c 8.1 (Berkeley) 6/6/93";
#else
-__RCSID("$NetBSD: buf.c,v 1.11 1997/09/28 03:31:00 lukem Exp $");
+__RCSID("$NetBSD: buf.c,v 1.12 1999/09/15 04:16:31 mycroft Exp $");
#endif
#endif /* not lint */
#endif
@@ -72,8 +72,8 @@
* buffer in case it holds a string.
*/
#define BufExpand(bp,nb) \
- if (bp->left < (nb)+1) {\
- int newSize = (bp)->size + max((nb)+1,BUF_ADD_INC); \
+ while (bp->left < (nb)+1) {\
+ int newSize = (bp)->size * 2; \
Byte *newBuf = (Byte *) erealloc((bp)->buffer, newSize); \
\
(bp)->inPtr = newBuf + ((bp)->inPtr - (bp)->buffer); \
@@ -84,8 +84,6 @@
}
#define BUF_DEF_SIZE 256 /* Default buffer size */
-#define BUF_ADD_INC 256 /* Expansion increment when Adding */
-#define BUF_UNGET_INC 16 /* Expansion increment when Ungetting */
/*-
*-----------------------------------------------------------------------
@@ -152,168 +150,6 @@
/*-
*-----------------------------------------------------------------------
- * Buf_UngetByte --
- * Place the byte back at the beginning of the buffer.
- *
- * Results:
- * SUCCESS if the byte was added ok. FAILURE if not.
- *
- * Side Effects:
- * The byte is stuffed in the buffer and outPtr is decremented.
- *
- *-----------------------------------------------------------------------
- */
-void
-Buf_UngetByte (bp, byte)
- register Buffer bp;
- int byte;
-{
-
- if (bp->outPtr != bp->buffer) {
- bp->outPtr--;
- *bp->outPtr = byte;
- } else if (bp->outPtr == bp->inPtr) {
- *bp->inPtr = byte;
- bp->inPtr++;
- bp->left--;
- *bp->inPtr = 0;
- } else {
- /*
- * Yech. have to expand the buffer to stuff this thing in.
- * We use a different expansion constant because people don't
- * usually push back many bytes when they're doing it a byte at
- * a time...
- */
- int numBytes = bp->inPtr - bp->outPtr;
- Byte *newBuf;
-
- newBuf = (Byte *)emalloc(bp->size + BUF_UNGET_INC);
- memcpy ((char *)(newBuf+BUF_UNGET_INC), (char *)bp->outPtr, numBytes+1);
- bp->outPtr = newBuf + BUF_UNGET_INC;
- bp->inPtr = bp->outPtr + numBytes;
- free ((char *)bp->buffer);
- bp->buffer = newBuf;
- bp->size += BUF_UNGET_INC;
- bp->left = bp->size - (bp->inPtr - bp->buffer);
- bp->outPtr -= 1;
- *bp->outPtr = byte;
- }
-}
-
-/*-
- *-----------------------------------------------------------------------
- * Buf_UngetBytes --
- * Push back a series of bytes at the beginning of the buffer.
- *
- * Results:
- * None.
- *
- * Side Effects:
- * outPtr is decremented and the bytes copied into the buffer.
- *
- *-----------------------------------------------------------------------
- */
-void
-Buf_UngetBytes (bp, numBytes, bytesPtr)
- register Buffer bp;
- int numBytes;
- Byte *bytesPtr;
-{
-
- if (bp->outPtr - bp->buffer >= numBytes) {
- bp->outPtr -= numBytes;
- memcpy (bp->outPtr, bytesPtr, numBytes);
- } else if (bp->outPtr == bp->inPtr) {
- Buf_AddBytes (bp, numBytes, bytesPtr);
- } else {
- int curNumBytes = bp->inPtr - bp->outPtr;
- Byte *newBuf;
- int newBytes = max(numBytes,BUF_UNGET_INC);
-
- newBuf = (Byte *)emalloc (bp->size + newBytes);
- memcpy((char *)(newBuf+newBytes), (char *)bp->outPtr, curNumBytes+1);
- bp->outPtr = newBuf + newBytes;
- bp->inPtr = bp->outPtr + curNumBytes;
- free ((char *)bp->buffer);
- bp->buffer = newBuf;
- bp->size += newBytes;
- bp->left = bp->size - (bp->inPtr - bp->buffer);
- bp->outPtr -= numBytes;
- memcpy ((char *)bp->outPtr, (char *)bytesPtr, numBytes);
- }
-}
-
-/*-
- *-----------------------------------------------------------------------
- * Buf_GetByte --
- * Return the next byte from the buffer. Actually returns an integer.
- *
- * Results:
- * Returns BUF_ERROR if there's no byte in the buffer, or the byte
- * itself if there is one.
- *
- * Side Effects:
- * outPtr is incremented and both outPtr and inPtr will be reset if
- * the buffer is emptied.
- *
- *-----------------------------------------------------------------------
- */
-int
-Buf_GetByte (bp)
- register Buffer bp;
-{
- int res;
-
- if (bp->inPtr == bp->outPtr) {
- return (BUF_ERROR);
- } else {
- res = (int) *bp->outPtr;
- bp->outPtr += 1;
- if (bp->outPtr == bp->inPtr) {
- bp->outPtr = bp->inPtr = bp->buffer;
- bp->left = bp->size;
- *bp->inPtr = 0;
- }
- return (res);
- }
-}
-
-/*-
- *-----------------------------------------------------------------------
- * Buf_GetBytes --
- * Extract a number of bytes from the buffer.
- *
- * Results:
- * The number of bytes gotten.
- *
- * Side Effects:
- * The passed array is overwritten.
- *
- *-----------------------------------------------------------------------
- */
-int
-Buf_GetBytes (bp, numBytes, bytesPtr)
- register Buffer bp;
- int numBytes;
- Byte *bytesPtr;
-{
-
- if (bp->inPtr - bp->outPtr < numBytes) {
- numBytes = bp->inPtr - bp->outPtr;
- }
- memcpy (bytesPtr, bp->outPtr, numBytes);
- bp->outPtr += numBytes;
-
- if (bp->outPtr == bp->inPtr) {
- bp->outPtr = bp->inPtr = bp->buffer;
- bp->left = bp->size;
- *bp->inPtr = 0;
- }
- return (numBytes);
-}
-
-/*-
- *-----------------------------------------------------------------------
* Buf_GetAll --
* Get all the available data at once.
*
diff -r d4796e568528 -r 2f94dfc9294d usr.bin/make/buf.h
--- a/usr.bin/make/buf.h Wed Sep 15 04:06:00 1999 +0000
+++ b/usr.bin/make/buf.h Wed Sep 15 04:16:31 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: buf.h,v 1.7 1996/12/31 17:53:22 christos Exp $ */
+/* $NetBSD: buf.h,v 1.8 1999/09/15 04:16:31 mycroft Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -69,10 +69,6 @@
void Buf_OvAddByte __P((Buffer, int));
void Buf_AddBytes __P((Buffer, int, const Byte *));
-void Buf_UngetByte __P((Buffer, int));
-void Buf_UngetBytes __P((Buffer, int, Byte *));
-int Buf_GetByte __P((Buffer));
-int Buf_GetBytes __P((Buffer, int, Byte *));
Byte *Buf_GetAll __P((Buffer, int *));
void Buf_Discard __P((Buffer, int));
int Buf_Size __P((Buffer));
Home |
Main Index |
Thread Index |
Old Index