File tree Expand file tree Collapse file tree 1 file changed +14
-28
lines changed
Expand file tree Collapse file tree 1 file changed +14
-28
lines changed Original file line number Diff line number Diff line change @@ -2008,6 +2008,12 @@ static void output(struct scoreboard *sb, int option)
20082008 }
20092009}
20102010
2011+ static const char * get_next_line (const char * start , const char * end )
2012+ {
2013+ const char * nl = memchr (start , '\n' , end - start );
2014+ return nl ? nl + 1 : end ;
2015+ }
2016+
20112017/*
20122018 * To allow quick access to the contents of nth line in the
20132019 * final image, prepare an index in the scoreboard.
@@ -2019,39 +2025,19 @@ static int prepare_lines(struct scoreboard *sb)
20192025 const char * end = buf + len ;
20202026 const char * p ;
20212027 int * lineno ;
2022- int num = 0 , incomplete = 0 ;
2023-
2024- for (p = buf ;;) {
2025- p = memchr (p , '\n' , end - p );
2026- if (p ) {
2027- p ++ ;
2028- num ++ ;
2029- continue ;
2030- }
2031- break ;
2032- }
2028+ int num = 0 ;
20332029
2034- if ( len && end [ -1 ] != '\n' )
2035- incomplete ++ ; /* incomplete line at the end */
2030+ for ( p = buf ; p < end ; p = get_next_line ( p , end ) )
2031+ num ++ ;
20362032
2037- sb -> lineno = xmalloc (sizeof (* sb -> lineno ) * (num + incomplete + 1 ));
2038- lineno = sb -> lineno ;
2033+ sb -> lineno = lineno = xmalloc (sizeof (* sb -> lineno ) * (num + 1 ));
20392034
2040- * lineno ++ = 0 ;
2041- for (p = buf ;;) {
2042- p = memchr (p , '\n' , end - p );
2043- if (p ) {
2044- p ++ ;
2045- * lineno ++ = p - buf ;
2046- continue ;
2047- }
2048- break ;
2049- }
2035+ for (p = buf ; p < end ; p = get_next_line (p , end ))
2036+ * lineno ++ = p - buf ;
20502037
2051- if (incomplete )
2052- * lineno ++ = len ;
2038+ * lineno = len ;
20532039
2054- sb -> num_lines = num + incomplete ;
2040+ sb -> num_lines = num ;
20552041 return sb -> num_lines ;
20562042}
20572043
You can’t perform that action at this time.
0 commit comments