Don't use "sscanf()" for tree mode scanning
authorLinus Torvalds <torvalds@osdl.org>
Sun, 28 May 2006 23:16:15 +0000 (16:16 -0700)
committerJunio C Hamano <junkio@cox.net>
Mon, 29 May 2006 02:39:49 +0000 (19:39 -0700)
commit7d65848afd42f075f6db0d03da2c9f5a9bac6267
tree761654bdea53ff66480876f7be670ccc0ca9ab9e
parent878ccb26941a15312b6676372e4688d42a73882b
Don't use "sscanf()" for tree mode scanning

Doing an oprofile run on the result of my git rev-list memory leak fixes
and tree parsing cleanups, I was surprised by the third-highest entry
being

samples  %        image name               app name                 symbol name
179751    2.7163  libc-2.4.so              libc-2.4.so              _IO_vfscanf@@GLIBC_2.4

where that 2.7% is actually more than 5% of one CPU, because this was run
on a dual CPU setup with the other CPU just being idle.

That seems to all be from the use of 'sscanf(tree, "%o", &mode)' for the
tree buffer parsing.

So do the trivial octal parsing by hand, which also gives us where the
first space in the string is (and thus where the pathname starts) so we
can get rid of the "strchr(tree, ' ')" call too.

This brings the "git rev-list --all --objects" time down from 63 seconds
to 55 seconds on the historical kernel archive for me, so it's quite
noticeable - tree parsing is a lot of what we end up doing when following
all the objects.

[ I also see a 5% speedup on a full "git fsck-objects" on the current
  kernel archive, so that sscanf() really does seem to have hurt our
  performance by a surprising amount ]

Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
tree-walk.c