lkml.org 
[lkml]   [2015]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: tools: usbip: detach: avoid calling strlen() at each iteration
Date
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



\
 
 \ /
  Last update: 2015-09-16 16:01    [W:0.048 / U:1.044 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site