Change in ...libosmocore[master]: utils: share static buffer in osmo_str_to{lower, upper}()

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/.

laforge gerrit-no-reply at lists.osmocom.org
Sat Aug 3 07:38:50 UTC 2019


laforge has submitted this change and it was merged. ( https://gerrit.osmocom.org/c/libosmocore/+/15024 )

Change subject: utils: share static buffer in osmo_str_to{lower,upper}()
......................................................................

utils: share static buffer in osmo_str_to{lower,upper}()

This way we get rid of extra 128 bytes in memory per thread created.
It makes sense to share the buffer since it's same size and it doesn't
make much sense to be using both osmo_str_tolower and osmo_strtoupper at
the same time (usually you either want to move everything to uppercase
or everything to lowerase). In required scenarios, one can still use the
_buf versions.

Change-Id: I032803faa0e27c2efdff1ff276acabab95a8319a
---
M src/utils.c
1 file changed, 8 insertions(+), 8 deletions(-)

Approvals:
  laforge: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/utils.c b/src/utils.c
index 7364bfb..ea1de0f 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -42,6 +42,8 @@
  * \file utils.c */
 
 static __thread char namebuf[255];
+/* shared by osmo_str_tolower() and osmo_str_toupper() */
+static __thread char capsbuf[128];
 
 /*! get human-readable string for given value
  *  \param[in] vs Array of value_string tuples
@@ -901,16 +903,15 @@
 /*! Convert a string to lowercase, using a static buffer.
  * The resulting string may be truncated if the internally used static buffer is shorter than src.
  * The internal buffer is at least 128 bytes long, i.e. guaranteed to hold at least 127 characters and a
- * terminating nul.
+ * terminating nul. The static buffer returned is shared with osmo_str_toupper().
  * See also osmo_str_tolower_buf().
  * \param[in] src  String to convert to lowercase.
  * \returns Resulting lowercase string in a static buffer, always nul terminated.
  */
 const char *osmo_str_tolower(const char *src)
 {
-	static __thread char buf[128];
-	osmo_str_tolower_buf(buf, sizeof(buf), src);
-	return buf;
+	osmo_str_tolower_buf(capsbuf, sizeof(capsbuf), src);
+	return capsbuf;
 }
 
 /*! Convert a string to lowercase, dynamically allocating the output from given talloc context
@@ -960,16 +961,15 @@
 /*! Convert a string to uppercase, using a static buffer.
  * The resulting string may be truncated if the internally used static buffer is shorter than src.
  * The internal buffer is at least 128 bytes long, i.e. guaranteed to hold at least 127 characters and a
- * terminating nul.
+ * terminating nul. The static buffer returned is shared with osmo_str_tolower().
  * See also osmo_str_toupper_buf().
  * \param[in] src  String to convert to uppercase.
  * \returns Resulting uppercase string in a static buffer, always nul terminated.
  */
 const char *osmo_str_toupper(const char *src)
 {
-	static __thread char buf[128];
-	osmo_str_toupper_buf(buf, sizeof(buf), src);
-	return buf;
+	osmo_str_toupper_buf(capsbuf, sizeof(capsbuf), src);
+	return capsbuf;
 }
 
 /*! Convert a string to uppercase, dynamically allocating the output from given talloc context

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/15024
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I032803faa0e27c2efdff1ff276acabab95a8319a
Gerrit-Change-Number: 15024
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <axilirator at gmail.com>
Gerrit-Reviewer: laforge <laforge at gnumonks.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190803/6b22cec0/attachment.htm>


More information about the gerrit-log mailing list