Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/makemandb Instead of dereferencing the pointer pass...
details: https://anonhg.NetBSD.org/src/rev/fe1c8cf9d6a1
branches: trunk
changeset: 353342:fe1c8cf9d6a1
user: abhinav <abhinav%NetBSD.org@localhost>
date: Sun Apr 30 15:27:24 2017 +0000
description:
Instead of dereferencing the pointer passed in as function argument, use a
temporary local buffer. Saves the cost of pointer dereferencing at so many places.
diffstat:
usr.sbin/makemandb/apropos-utils.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)
diffs (60 lines):
diff -r 81fcd9459b7d -r fe1c8cf9d6a1 usr.sbin/makemandb/apropos-utils.c
--- a/usr.sbin/makemandb/apropos-utils.c Sun Apr 30 14:53:58 2017 +0000
+++ b/usr.sbin/makemandb/apropos-utils.c Sun Apr 30 15:27:24 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apropos-utils.c,v 1.34 2017/04/30 14:53:58 abhinav Exp $ */
+/* $NetBSD: apropos-utils.c,v 1.35 2017/04/30 15:27:24 abhinav Exp $ */
/*-
* Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
* All rights reserved.
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: apropos-utils.c,v 1.34 2017/04/30 14:53:58 abhinav Exp $");
+__RCSID("$NetBSD: apropos-utils.c,v 1.35 2017/04/30 15:27:24 abhinav Exp $");
#include <sys/queue.h>
#include <sys/stat.h>
@@ -111,31 +111,34 @@
concat2(char **dst, const char *src, size_t srclen)
{
size_t totallen, dstlen;
+ char *mydst = *dst;
assert(src != NULL);
/*
* If destination buffer dst is NULL, then simply
* strdup the source buffer
*/
- if (*dst == NULL) {
- *dst = estrndup(src, srclen);
+ if (mydst == NULL) {
+ mydst = estrndup(src, srclen);
+ *dst = mydst;
return;
}
- dstlen = strlen(*dst);
+ dstlen = strlen(mydst);
/*
* NUL Byte and separator space
*/
totallen = dstlen + srclen + 2;
- *dst = erealloc(*dst, totallen);
+ mydst = erealloc(mydst, totallen);
/* Append a space at the end of dst */
- (*dst)[dstlen++] = ' ';
+ mydst[dstlen++] = ' ';
/* Now, copy src at the end of dst */
- memcpy(*dst + dstlen, src, srclen);
- (*dst)[dstlen + srclen] = '\0';
+ memcpy(mydst + dstlen, src, srclen);
+ mydst[dstlen + srclen] = '\0';
+ *dst = mydst;
}
void
Home |
Main Index |
Thread Index |
Old Index