[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master d00a10333f0 1/3: Use strnlen to avoid unnecessary work in pgtkfns
From: |
Stefan Kangas |
Subject: |
master d00a10333f0 1/3: Use strnlen to avoid unnecessary work in pgtkfns.c |
Date: |
Thu, 18 Jul 2024 09:20:00 -0400 (EDT) |
branch: master
commit d00a10333f06d30fee93ba3ee033e74dc4ff85bc
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>
Use strnlen to avoid unnecessary work in pgtkfns.c
* src/pgtkfns.c (pgtk_get_defaults_value, pgtk_set_defaults_value):
Factor out new function...
(pgtk_check_resource_key_length): ...to here. Avoid unnecessary work by
using strnlen.
---
src/pgtkfns.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/pgtkfns.c b/src/pgtkfns.c
index b8e65f4c052..f1c0e5da0f3 100644
--- a/src/pgtkfns.c
+++ b/src/pgtkfns.c
@@ -1901,13 +1901,19 @@ parse_resource_key (const char *res_key, char
*setting_key)
return gs;
}
+static void
+pgtk_check_resource_key_length (const char *key)
+{
+ if (strnlen (key, RESOURCE_KEY_MAX_LEN) >= RESOURCE_KEY_MAX_LEN)
+ error ("Resource key too long");
+}
+
const char *
pgtk_get_defaults_value (const char *key)
{
char skey[(RESOURCE_KEY_MAX_LEN + 1) * 2];
- if (strlen (key) >= RESOURCE_KEY_MAX_LEN)
- error ("Resource key too long");
+ pgtk_check_resource_key_length (key);
GSettings *gs = parse_resource_key (key, skey);
if (gs == NULL)
@@ -1936,8 +1942,7 @@ pgtk_set_defaults_value (const char *key, const char
*value)
{
char skey[(RESOURCE_KEY_MAX_LEN + 1) * 2];
- if (strlen (key) >= RESOURCE_KEY_MAX_LEN)
- error ("Resource key too long");
+ pgtk_check_resource_key_length (key);
GSettings *gs = parse_resource_key (key, skey);
if (gs == NULL)