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>
1 file changed
tree: 761654bdea53ff66480876f7be670ccc0ca9ab9e
  1. arm/
  2. compat/
  3. contrib/
  4. Documentation/
  5. mozilla-sha1/
  6. ppc/
  7. t/
  8. templates/
  9. xdiff/
  10. .gitignore
  11. base85.c
  12. blame.c
  13. blob.c
  14. blob.h
  15. builtin-add.c
  16. builtin-apply.c
  17. builtin-cat-file.c
  18. builtin-check-ref-format.c
  19. builtin-commit-tree.c
  20. builtin-count.c
  21. builtin-diff-files.c
  22. builtin-diff-index.c
  23. builtin-diff-stages.c
  24. builtin-diff-tree.c
  25. builtin-diff.c
  26. builtin-grep.c
  27. builtin-help.c
  28. builtin-init-db.c
  29. builtin-log.c
  30. builtin-ls-files.c
  31. builtin-ls-tree.c
  32. builtin-push.c
  33. builtin-read-tree.c
  34. builtin-rev-list.c
  35. builtin-rm.c
  36. builtin-show-branch.c
  37. builtin-tar-tree.c
  38. builtin-upload-tar.c
  39. builtin.h
  40. cache.h
  41. checkout-index.c
  42. clone-pack.c
  43. combine-diff.c
  44. commit.c
  45. commit.h
  46. config.c
  47. connect.c
  48. convert-objects.c
  49. copy.c
  50. COPYING
  51. csum-file.c
  52. csum-file.h
  53. ctype.c
  54. daemon.c
  55. date.c
  56. delta.h
  57. describe.c
  58. diff-delta.c
  59. diff-lib.c
  60. diff.c
  61. diff.h
  62. diffcore-break.c
  63. diffcore-delta.c
  64. diffcore-order.c
  65. diffcore-pickaxe.c
  66. diffcore-rename.c
  67. diffcore.h
  68. dir.c
  69. dir.h
  70. entry.c
  71. environment.c
  72. exec_cmd.c
  73. exec_cmd.h
  74. fetch-clone.c
  75. fetch-pack.c
  76. fetch.c
  77. fetch.h
  78. fsck-objects.c
  79. generate-cmdlist.sh
  80. get-tar-commit-id.c
  81. git-am.sh
  82. git-annotate.perl
  83. git-applymbox.sh
  84. git-applypatch.sh
  85. git-archimport.perl
  86. git-bisect.sh
  87. git-branch.sh
  88. git-checkout.sh
  89. git-cherry.sh
  90. git-clean.sh
  91. git-clone.sh
  92. git-commit.sh
  93. git-compat-util.h
  94. git-cvsexportcommit.perl
  95. git-cvsimport.perl
  96. git-cvsserver.perl
  97. git-fetch.sh
  98. git-fmt-merge-msg.perl
  99. git-lost-found.sh
  100. git-ls-remote.sh
  101. git-merge-octopus.sh
  102. git-merge-one-file.sh
  103. git-merge-ours.sh
  104. git-merge-recursive.py
  105. git-merge-resolve.sh
  106. git-merge-stupid.sh
  107. git-merge.sh
  108. git-mv.perl
  109. git-parse-remote.sh
  110. git-prune.sh
  111. git-pull.sh
  112. git-push.sh
  113. git-quiltimport.sh
  114. git-rebase.sh
  115. git-relink.perl
  116. git-repack.sh
  117. git-request-pull.sh
  118. git-rerere.perl
  119. git-reset.sh
  120. git-resolve.sh
  121. git-revert.sh
  122. git-send-email.perl
  123. git-sh-setup.sh
  124. git-shortlog.perl
  125. git-svnimport.perl
  126. git-tag.sh
  127. git-verify-tag.sh
  128. GIT-VERSION-GEN
  129. git.c
  130. git.spec.in
  131. gitk
  132. gitMergeCommon.py
  133. hash-object.c
  134. http-fetch.c
  135. http-push.c
  136. http.c
  137. http.h
  138. ident.c
  139. imap-send.c
  140. index-pack.c
  141. index.c
  142. INSTALL
  143. local-fetch.c
  144. log-tree.c
  145. log-tree.h
  146. mailinfo.c
  147. mailsplit.c
  148. Makefile
  149. merge-base.c
  150. merge-index.c
  151. merge-tree.c
  152. mktag.c
  153. mktree.c
  154. name-rev.c
  155. object.c
  156. object.h
  157. pack-check.c
  158. pack-objects.c
  159. pack-redundant.c
  160. pack.h
  161. pager.c
  162. patch-delta.c
  163. patch-id.c
  164. path.c
  165. peek-remote.c
  166. pkt-line.c
  167. pkt-line.h
  168. prune-packed.c
  169. quote.c
  170. quote.h
  171. read-cache.c
  172. README
  173. receive-pack.c
  174. refs.c
  175. refs.h
  176. repo-config.c
  177. rev-parse.c
  178. revision.c
  179. revision.h
  180. rsh.c
  181. rsh.h
  182. run-command.c
  183. run-command.h
  184. send-pack.c
  185. server-info.c
  186. setup.c
  187. sha1_file.c
  188. sha1_name.c
  189. shell.c
  190. show-index.c
  191. ssh-fetch.c
  192. ssh-pull.c
  193. ssh-push.c
  194. ssh-upload.c
  195. strbuf.c
  196. strbuf.h
  197. stripspace.c
  198. symbolic-ref.c
  199. tag.c
  200. tag.h
  201. tar.h
  202. test-date.c
  203. test-delta.c
  204. tree-diff.c
  205. tree-walk.c
  206. tree-walk.h
  207. tree.c
  208. tree.h
  209. unpack-file.c
  210. unpack-objects.c
  211. update-index.c
  212. update-ref.c
  213. update-server-info.c
  214. upload-pack.c
  215. usage.c
  216. var.c
  217. verify-pack.c
  218. write-tree.c
  219. xdiff-interface.c
  220. xdiff-interface.h