Skip to content
  • Linus Torvalds's avatar
    Avoid unnecessary strlen() calls · 304de2d2
    Linus Torvalds authored
    
    
    This is a micro-optimization that grew out of the mailing list discussion
    about "strlen()" showing up in profiles.
    
    We used to pass regular C strings around to the low-level tree walking
    routines, and while this worked fine, it meant that we needed to call
    strlen() on strings that the caller always actually knew the size of
    anyway.
    
    So pass the length of the string down wih the string, and avoid
    unnecessary calls to strlen(). Also, when extracting a pathname from a
    tree entry, use "tree_entry_len()" instead of strlen(), since the length
    of the pathname is directly calculable from the decoded tree entry itself
    without having to actually do another strlen().
    
    This shaves off another ~5-10% from some loads that are very tree
    intensive (notably doing commit filtering by a pathspec).
    
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org&gt;">
    Signed-off-by: default avatarJunio C Hamano <junkio@cox.net>
    304de2d2