aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorAlexey Lapshin <alexey.lapshin@espressif.com>2025-01-27 10:50:36 +0000
committerCorinna Vinschen <corinna@vinschen.de>2025-02-10 15:33:35 +0100
commit9a706d0479af5691f14a57a1114215c03c8d3d63 (patch)
tree0da193474a22f873fa6e8c902dc7ee3416a950cd /newlib
parent2a79b76c077af110ed95590a4eafbe13faff5bf9 (diff)
downloadnewlib-9a706d0479af5691f14a57a1114215c03c8d3d63.zip
newlib-9a706d0479af5691f14a57a1114215c03c8d3d63.tar.gz
newlib-9a706d0479af5691f14a57a1114215c03c8d3d63.tar.bz2
newlib: str[n]cat: optimize skipping of the destination string
Prepare pointer to be aligned and than use word-size iterator on aligned memory.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/libc/string/strcat.c18
-rw-r--r--newlib/libc/string/strncat.c17
2 files changed, 18 insertions, 17 deletions
diff --git a/newlib/libc/string/strcat.c b/newlib/libc/string/strcat.c
index 71dd1db..47c53a5 100644
--- a/newlib/libc/string/strcat.c
+++ b/newlib/libc/string/strcat.c
@@ -50,17 +50,17 @@ strcat (char *__restrict s1,
#else
char *s = s1;
+ /* Skip unaligned memory in s1. */
+ while (UNALIGNED_X(s1) && *s1)
+ s1++;
- /* Skip over the data in s1 as quickly as possible. */
- if (!UNALIGNED_X(s1))
- {
- unsigned long *aligned_s1 = (unsigned long *)s1;
- while (!DETECT_NULL(*aligned_s1))
- aligned_s1++;
-
- s1 = (char *)aligned_s1;
- }
+ /* Skip over the aligned data in s1 as quickly as possible. */
+ unsigned long *aligned_s1 = (unsigned long *)s1;
+ while (!DETECT_NULL(*aligned_s1))
+ aligned_s1++;
+ s1 = (char *)aligned_s1;
+ /* Find string terminator. */
while (*s1)
s1++;
diff --git a/newlib/libc/string/strncat.c b/newlib/libc/string/strncat.c
index 01f20f6..fc9fe5b 100644
--- a/newlib/libc/string/strncat.c
+++ b/newlib/libc/string/strncat.c
@@ -59,16 +59,17 @@ strncat (char *__restrict s1,
#else
char *s = s1;
- /* Skip over the data in s1 as quickly as possible. */
- if (!UNALIGNED_X(s1))
- {
- unsigned long *aligned_s1 = (unsigned long *)s1;
- while (!DETECT_NULL(*aligned_s1))
- aligned_s1++;
+ /* Skip unaligned memory in s1. */
+ while (UNALIGNED_X(s1) && *s1)
+ s1++;
- s1 = (char *)aligned_s1;
- }
+ /* Skip over the aligned data in s1 as quickly as possible. */
+ unsigned long *aligned_s1 = (unsigned long *)s1;
+ while (!DETECT_NULL(*aligned_s1))
+ aligned_s1++;
+ s1 = (char *)aligned_s1;
+ /* Find string terminator. */
while (*s1)
s1++;