From: Eric Curtin <ericcurtin17@gmail.com>
To: valentina.manea.m@gmail.com, shuah.kh@samsung.com
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: tools: usbip: detach: avoid calling strlen() at each iteration
Date: Tue, 15 Sep 2015 21:27:20 +0100 [thread overview]
Message-ID: <1442348840-32025-1-git-send-email-ericcurtin17@gmail.com> (raw)
Instead of calling strlen on every iteration of the for loop, just call it
once and cache the result in a temporary local variable which will be used
in the for loop instead.
Signed-off-by: Eric Curtin <ericcurtin17@gmail.com>
diff --git a/tools/usb/usbip/src/usbip_detach.c b/tools/usb/usbip/src/usbip_detach.c
index 05c6d15..9db9d21 100644
--- a/tools/usb/usbip/src/usbip_detach.c
+++ b/tools/usb/usbip/src/usbip_detach.c
@@ -47,7 +47,9 @@ static int detach_port(char *port)
uint8_t portnum;
char path[PATH_MAX+1];
- for (unsigned int i = 0; i < strlen(port); i++)
+ unsigned int port_len = strlen(port);
+
+ for (unsigned int i = 0; i < port_len; i++)
if (!isdigit(port[i])) {
err("invalid port %s", port);
return -1;
next reply other threads:[~2015-09-15 20:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-15 20:27 Eric Curtin [this message]
2015-09-15 20:55 ` tools: usbip: detach: avoid calling strlen() at each iteration Aaro Koskinen
2015-09-16 7:25 ` Clemens Ladisch
2015-09-16 13:44 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1442348840-32025-1-git-send-email-ericcurtin17@gmail.com \
--to=ericcurtin17@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=shuah.kh@samsung.com \
--cc=valentina.manea.m@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.