To answer your question, strlen+strcmp is a habit learned from using
multiple languages and seeing cases where /home/okra/foo and
/home/okra/foobar would return equal and they are most certainly not.  Has
nothing to do with optimizations.  strncmp doesn't work in this case
because you don't know how many characters of the second string there are
in the directory path of the file without a dirname or strrchr.  So I know
the directory name I want is /home/okra/foo and that is 14 characters but
strncmp(/home/okra/foo, /home/okra/foobar, 14) would return equal, and they
are not.

On Tue, Jan 19, 2016 at 5:07 PM, Davide Andreoli <d...@gurumeditation.it>
wrote:

> 2016-01-19 22:11 GMT+01:00 Stephen Houston <smhousto...@gmail.com>:
>
> > okra pushed a commit to branch master.
> >
> >
> >
> http://git.enlightenment.org/apps/ephoto.git/commit/?id=ff28d742535f18691f9e7985c70612bed2c759ba
> >
> > commit ff28d742535f18691f9e7985c70612bed2c759ba
> > Author: Stephen Houston <smhousto...@gmail.com>
> > Date:   Tue Jan 19 15:10:37 2016 -0600
> >
> >     Ephoto: Only update thumbs on monitor call when the thumb is in the
> > current directory.
> > ---
> >  src/bin/ephoto_main.c | 30 ++++++++++++++++++++++++++++++
> >  1 file changed, 30 insertions(+)
> >
> > diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c
> > index d27c1d0..858ed06 100644
> > --- a/src/bin/ephoto_main.c
> > +++ b/src/bin/ephoto_main.c
> > @@ -462,6 +462,16 @@ _monitor_created(void *data, int type EINA_UNUSED,
> > void *event)
> >  {
> >     Ephoto *ephoto = data;
> >     Eio_Monitor_Event *ev = event;
> > +   char file[PATH_MAX], dir[PATH_MAX], p[PATH_MAX];
> > +
> > +   snprintf(file, PATH_MAX, "%s", ev->filename);
> > +   snprintf(p, PATH_MAX, "%s", ephoto->config->directory);
> > +   snprintf(dir, PATH_MAX, "%s", dirname(file));
> > +
> > +   if (strlen(p) != strlen(dir))
> > +     return ECORE_CALLBACK_PASS_ON;
> > +   if (strcmp(p, dir))
> > +     return ECORE_CALLBACK_PASS_ON;
> >
> > This last 4 lines catch my curiosity-monkey :)
>
> Is this a tentative of optimization? (first check len and then strcmp if
> they are equal)
> If yes, then I think you failed on that (unless I miss some obscure
> compiler optimizations), strlen need to
> scan the whole string (2 strings in your case) to return the length, while
> strcmp return as soon as the
> 2 strings have a first different byte. So usually strlen is slower than
> strcmp
>
> for reference this is a strlen implementation:
> http://www.stdlib.net/~colmmacc/strlen.c.html (really interesting the
> optimizations here)
>
> and a strcmp one:
> http://www.opensource.apple.com/source/Libc/Libc-262/ppc/gen/strcmp.c
>
>
> I also suggest the strNcmp function, can probably be useful for this case
> to avoid the snprintf()+dirname() call ?
>
> ------------------------------------------------------------------------------
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
> _______________________________________________
> enlightenment-devel mailing list
> enlightenment-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
>
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to