浏览代码

tools: usbip: detach: avoid calling strlen() at each iteration

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Eric Curtin 10 年之前
父节点
当前提交
0c61814544
共有 1 个文件被更改,包括 3 次插入1 次删除
  1. 3 1
      tools/usb/usbip/src/usbip_detach.c

+ 3 - 1
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;