[MERGED] libosmocore[master]: core/conv/conv_acc.c: use static allocation for vdecoder

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Mon Jun 19 14:35:23 UTC 2017


Vadim Yanitskiy has submitted this change and it was merged.

Change subject: core/conv/conv_acc.c: use static allocation for vdecoder
......................................................................


core/conv/conv_acc.c: use static allocation for vdecoder

Allocation of a new memory is an expensive operation, which
takes place when it's initially unknown, how much memory will
we need, or in order to decrease total memory usage.

The vdecoder struct wasn't require dynamic allocation itself,
so let's use static allocation in order to increase performance.

Change-Id: Id1b140d3cb61db7352dcfc217a8fc36091e945ab
---
M src/conv_acc.c
1 file changed, 19 insertions(+), 23 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/conv_acc.c b/src/conv_acc.c
index 7f03628..f45d50f 100644
--- a/src/conv_acc.c
+++ b/src/conv_acc.c
@@ -498,7 +498,7 @@
 }
 
 /* Release decoder object */
-static void free_vdec(struct vdecoder *dec)
+static void vdec_deinit(struct vdecoder *dec)
 {
 	if (!dec)
 		return;
@@ -509,22 +509,18 @@
 		vdec_free(dec->paths[0]);
 		free(dec->paths);
 	}
-
-	free(dec);
 }
 
-/* Allocate decoder object
+/* Initialize decoder object with code specific params
  * Subtract the constraint length K on the normalization interval to
  * accommodate the initialization path metric at state zero.
  */
-static struct vdecoder *alloc_vdec(const struct osmo_conv_code *code)
+static int vdec_init(struct vdecoder *dec, const struct osmo_conv_code *code)
 {
 	int i, ns;
-	struct vdecoder *dec;
 
 	ns = NUM_STATES(code->K);
 
-	dec = (struct vdecoder *) calloc(1, sizeof(struct vdecoder));
 	dec->n = code->N;
 	dec->k = code->K;
 	dec->recursive = conv_code_recursive(code);
@@ -542,7 +538,7 @@
 			dec->metric_func = osmo_conv_metrics_k5_n4;
 			break;
 		default:
-			goto fail;
+			return -EINVAL;
 		}
 	} else if (dec->k == 7) {
 		switch (dec->n) {
@@ -556,10 +552,10 @@
 			dec->metric_func = osmo_conv_metrics_k7_n4;
 			break;
 		default:
-			goto fail;
+			return -EINVAL;
 		}
 	} else {
-		goto fail;
+		return -EINVAL;
 	}
 
 	if (code->term == CONV_TERM_FLUSH)
@@ -569,24 +565,24 @@
 
 	dec->trellis = generate_trellis(code);
 	if (!dec->trellis)
-		goto fail;
+		goto enomem;
 
 	dec->paths = (int16_t **) malloc(sizeof(int16_t *) * dec->len);
 	if (!dec->paths)
-		goto fail;
+		goto enomem;
 
 	dec->paths[0] = vdec_malloc(ns * dec->len);
 	if (!dec->paths[0])
-		goto fail;
+		goto enomem;
 
 	for (i = 1; i < dec->len; i++)
 		dec->paths[i] = &dec->paths[0][i * ns];
 
-	return dec;
+	return 0;
 
-fail:
-	free_vdec(dec);
-	return NULL;
+enomem:
+	vdec_deinit(dec);
+	return -ENOMEM;
 }
 
 /* Depuncture sequence with nagative value terminated puncturing matrix */
@@ -697,7 +693,7 @@
 	const sbit_t *input, ubit_t *output)
 {
 	int rc;
-	struct vdecoder *vdec;
+	struct vdecoder dec;
 
 	if (!init_complete)
 		osmo_conv_init();
@@ -706,14 +702,14 @@
 		((code->K != 5) && (code->K != 7)))
 		return -EINVAL;
 
-	vdec = alloc_vdec(code);
-	if (!vdec)
-		return -EFAULT;
+	rc = vdec_init(&dec, code);
+	if (rc)
+		return rc;
 
-	rc = conv_decode(vdec, input, code->puncture,
+	rc = conv_decode(&dec, input, code->puncture,
 		output, code->len, code->term);
 
-	free_vdec(vdec);
+	vdec_deinit(&dec);
 
 	return rc;
 }

-- 
To view, visit https://gerrit.osmocom.org/2968
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id1b140d3cb61db7352dcfc217a8fc36091e945ab
Gerrit-PatchSet: 4
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Tom Tsou <tom at tsou.cc>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list