void-packages/srcpkgs/proplib/patches/avoid-extra-alloc-free.patch
2019-01-01 08:45:17 +01:00

52 lines
1.8 KiB
Diff

From 903e696b47fc469004598a5671965b31e902c544 Mon Sep 17 00:00:00 2001
From: Juan RP <xtraeme@gmail.com>
Date: Sun, 11 Jan 2015 17:07:55 +0100
Subject: [PATCH] prop_zlib: use a stack buffer to avoid an extra alloc/free.
Merged from xbps.
---
src/prop_zlib.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git src/prop_zlib.c src/prop_zlib.c
index f764eee..539ee76 100644
--- src/prop_zlib.c
+++ src/prop_zlib.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2010-2012 Juan Romero Pardines.
+ * Copyright (c) 2010-2014 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,7 +58,7 @@ prop ## type ## _internalize_from_zfile(const char *fname) \
struct _prop_object_internalize_mapped_file *mf; \
prop ## type ## _t obj = NULL; \
z_stream strm; \
- unsigned char *out; \
+ unsigned char out[_READ_CHUNK+1]; \
char *uncomp_xml = NULL; \
size_t have; \
ssize_t totalsize = 0; \
@@ -78,13 +78,6 @@ prop ## type ## _internalize_from_zfile(const char *fname) \
if (uncomp_xml == NULL) \
goto out; \
\
- /* temporary output buffer for inflate */ \
- out = _PROP_MALLOC(_READ_CHUNK, M_TEMP); \
- if (out == NULL) { \
- _PROP_FREE(uncomp_xml, M_TEMP); \
- goto out; \
- } \
- \
/* Decompress the mmap'ed buffer with zlib */ \
strm.zalloc = Z_NULL; \
strm.zfree = Z_NULL; \
@@ -123,7 +116,6 @@ out2: \
(void)inflateEnd(&strm); \
out1: \
obj = prop ## type ## _internalize(uncomp_xml); \
- _PROP_FREE(out, M_TEMP); \
_PROP_FREE(uncomp_xml, M_TEMP); \
out: \
_prop_object_internalize_unmap_file(mf); \