From b411ee115fb5e95c10cbd3e8012c50dc2e0e722c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Thu, 11 Jan 2007 20:28:02 +0000 Subject: [PATCH] Replaced two strstr by a hand-written loop in this critical code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2007-01-11 Benoît Dejean * glibtop_private.c: (get_scaled): Replaced two strstr by a hand-written loop in this critical code. svn path=/trunk/; revision=2544 --- sysdeps/linux/ChangeLog | 6 ++++++ sysdeps/linux/glibtop_private.c | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 90927f2d..1f06d345 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,9 @@ +2007-01-11 Benoît Dejean + + * glibtop_private.c: (get_scaled): + + Replaced two strstr by a hand-written loop in this critical code. + 2006-09-11 Benoît Dejean * procmap.c: (glibtop_get_proc_map_s): diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c index 490e1728..e93f8397 100644 --- a/sysdeps/linux/glibtop_private.c +++ b/sysdeps/linux/glibtop_private.c @@ -25,10 +25,16 @@ get_scaled(const char *buffer, const char *key) { ptr += strlen(key); value = strtoull(ptr, &next, 0); - if (strchr(next, 'k')) - value *= 1024; - else if (strchr(next, 'M')) - value *= 1024 * 1024; + + for ( ; *next; ++next) { + if (*next == 'k') { + value *= 1024; + break; + } else if (*next == 'M') { + value *= 1024 * 1024; + break; + } + } } else g_warning("Could not read key '%s' in buffer '%s'", key, buffer);