aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2019-08-01 18:11:41 +0200
committerPau Espin Pedrol <pespin@sysmocom.de>2019-08-02 20:08:13 +0200
commita37f58e98a28a8249178659ff3608203f5503772 (patch)
tree71a2b9fb528c666d77550134fbaa45f338e94f04 /src
parent513b2e34789b1125d44105aaadab8a3ae3493c5b (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/utils.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/utils.c b/src/utils.c
index 7364bfb1..ea1de0f5 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 @@ size_t osmo_str_tolower_buf(char *dest, size_t dest_len, const char *src)
/*! 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 @@ size_t osmo_str_toupper_buf(char *dest, size_t dest_len, const char *src)
/*! 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