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)
2008
2008
}
2009
2009
}
2010
2010
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
+
2011
2017
/*
2012
2018
* To allow quick access to the contents of nth line in the
2013
2019
* final image, prepare an index in the scoreboard.
@@ -2019,39 +2025,19 @@ static int prepare_lines(struct scoreboard *sb)
2019
2025
const char * end = buf + len ;
2020
2026
const char * p ;
2021
2027
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 ;
2033
2029
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 ++ ;
2036
2032
2037
- sb -> lineno = xmalloc (sizeof (* sb -> lineno ) * (num + incomplete + 1 ));
2038
- lineno = sb -> lineno ;
2033
+ sb -> lineno = lineno = xmalloc (sizeof (* sb -> lineno ) * (num + 1 ));
2039
2034
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 ;
2050
2037
2051
- if (incomplete )
2052
- * lineno ++ = len ;
2038
+ * lineno = len ;
2053
2039
2054
- sb -> num_lines = num + incomplete ;
2040
+ sb -> num_lines = num ;
2055
2041
return sb -> num_lines ;
2056
2042
}
2057
2043
You can’t perform that action at this time.
0 commit comments