From 0a0ce800217b40a28e3b2d92b485dbd63b5a384c Mon Sep 17 00:00:00 2001 From: drepper Date: Sat, 7 Jul 2001 22:52:21 +0000 Subject: [PATCH] Call strnlen() when determining the string length rather than strlen(). Solves the performance problem of doing strlen on a 5MB string when strncpy was called with a length argument of 5 bytes. --- sysdeps/ia64/strncpy.S | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sysdeps/ia64/strncpy.S b/sysdeps/ia64/strncpy.S index 17d677227f..051fefa05c 100644 --- a/sysdeps/ia64/strncpy.S +++ b/sysdeps/ia64/strncpy.S @@ -25,8 +25,8 @@ in1: src in2: char count - If n >= 24, do a memcpy(dest, src, min(strlen(src)+1, n)), followed by a - memset(dest + strlen(src), 0, n - strlen(src) - 1) if necessary. + If n >= 24, do a memcpy(dest, src, min(strnlen(src, n)+1, n)), followed by a + memset(dest + strlen(src, n), 0, n - strlen(src, n) - 1) if necessary. Otherwise, copy characters one by one and fill with nulls if necessary. */ @@ -58,8 +58,9 @@ ENTRY(strncpy) cmp.gtu p6, p0 = 24, n (p6) br.cond.spnt .cpyfew mov out0 = src - mov tmp = gp ;; - br.call.sptk.many b0 = strlen# ;; // rc = strlen(src); + mov out1 = n + mov tmp = gp + br.call.sptk.many b0 = strnlen# ;; // rc = strnlen(src, n); add len = 1, rc // include the null in len mov gp = tmp mov out0 = dest ;; -- 2.11.0