summaryrefslogtreecommitdiffstats
path: root/lib/stream.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2018-08-02 19:42:15 +0200
committerDonald Sharp <sharpd@cumulusnetworks.com>2018-08-02 20:57:44 +0200
commit565b5561acffc598b8ef8b99a7e6fb77e37f9257 (patch)
tree94407272903094c68d9e96edd5b23348df8e2bfc /lib/stream.c
parentMerge pull request #2760 from donaldsharp/bgp_patch_from_dev (diff)
downloadfrr-565b5561acffc598b8ef8b99a7e6fb77e37f9257.tar.xz
frr-565b5561acffc598b8ef8b99a7e6fb77e37f9257.zip
lib: Increase stream allocation speed.
Modify stream_new in this way: 1) ALLOC allocations do not fail, they cause a crash so remove if tests for it. 2) Modify usage of XCALLOC to XMALLOC and then hand set all the relevant data in the stream pointer. With this modification stream allocation of 10000000 streams at 10k bytes each reduced from on average 1.43 seconds to 0.65 seconds. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib/stream.c')
-rw-r--r--lib/stream.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/stream.c b/lib/stream.c
index a172eedc9..cf9af4d3b 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -100,16 +100,12 @@ struct stream *stream_new(size_t size)
assert(size > 0);
- s = XCALLOC(MTYPE_STREAM, sizeof(struct stream));
+ s = XMALLOC(MTYPE_STREAM, sizeof(struct stream));
- if (s == NULL)
- return s;
-
- if ((s->data = XMALLOC(MTYPE_STREAM_DATA, size)) == NULL) {
- XFREE(MTYPE_STREAM, s);
- return NULL;
- }
+ s->data = XMALLOC(MTYPE_STREAM_DATA, size);
+ s->getp = s->endp = 0;
+ s->next = NULL;
s->size = size;
return s;
}