Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1226096
| From | David Laight <David.Laight@ACULAB.COM> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | RE: tools: usbip: detach: avoid calling strlen() at each iteration |
| Date | 2015-09-16 15:50 +0200 |
| Message-ID | <q9lfY-64l-35@gated-at.bofh.it> (permalink) |
| References | <q951x-7Hp-35@gated-at.bofh.it> <q95Ed-vd-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Aaro Koskinen > Sent: 15 September 2015 21:56 ... > > - for (unsigned int i = 0; i < strlen(port); i++) > > + unsigned int port_len = strlen(port); > > + > > + for (unsigned int i = 0; i < port_len; i++) > > port is read only in this function, so maybe just use "const" and the > compiler should know to do the same without adding a new variable? While I've seen the compiler make the assumption, I'm not sure it should assume that data that is 'const' in one function cannot be modified by a called function. (Unless the compiler has some way of knowing that the called function cannot obtain a non-const pointer to the referenced data.) (This is also independent of whether the const pointer is passed to the function.) David -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Back to linux.kernel | Previous | Next — Previous in thread | Find similar | Unroll thread
tools: usbip: detach: avoid calling strlen() at each iteration Eric Curtin <ericcurtin17@gmail.com> - 2015-09-15 22:30 +0200
Re: tools: usbip: detach: avoid calling strlen() at each iteration Aaro Koskinen <aaro.koskinen@iki.fi> - 2015-09-15 23:10 +0200
Re: tools: usbip: detach: avoid calling strlen() at each iteration Clemens Ladisch <clemens@ladisch.de> - 2015-09-16 09:40 +0200
RE: tools: usbip: detach: avoid calling strlen() at each iteration David Laight <David.Laight@ACULAB.COM> - 2015-09-16 15:50 +0200
csiph-web