[Kst] kdeextragear-2/kst/kst
George Staikos
staikos at kde.org
Fri Oct 3 06:46:25 CEST 2003
CVS commit by staikos:
statistical optimisations in the ascii file reading code - check the common
case before the uncommon case.
M +14 -9 kstfile.cpp 1.23
--- kdeextragear-2/kst/kst/kstfile.cpp #1.22:1.23
@@ -494,32 +494,37 @@ bool KstFile::asciiUpdate(){
is_comment = has_dat = false;
- for (i_buf=0; i_buf<bufread; i_buf++) {
+ for (i_buf = 0; i_buf < bufread; i_buf++) {
if (tmpbuf[i_buf] == '\n') {
if (has_dat) {
NumFrames++;
- if (NumFrames>=NumLinesAlloc) {
+ if (NumFrames >= NumLinesAlloc) {
RowIndex = (int *)realloc(RowIndex,
(NumLinesAlloc + 32768)*sizeof(int));
NumLinesAlloc += 32768;
}
- new_data=true;
+ new_data = true;
}
RowIndex[NumFrames] = bufstart + i_buf+1;
has_dat = is_comment = false;
- } else if ((tmpbuf[i_buf] == '#') || (tmpbuf[i_buf] == '!') ||
- (tmpbuf[i_buf] == '/') || (tmpbuf[i_buf] == ';') ||
- (tmpbuf[i_buf] == 'c')) {
- is_comment = true;
+ // Statistically numbers should be more common than comments, so let's
+ // check for them first
+ // if isdigit() generates a function call, it would be better to write
+ // this inline, but I'm not convinced that compilers are that stupid yet.
+ // Profiling shows this code path gets hit 10^5+ times.
} else if (isdigit(tmpbuf[i_buf])) {
if (!is_comment) {
has_dat = true;
}
+ } else if (tmpbuf[i_buf] == '#' || tmpbuf[i_buf] == '!' ||
+ tmpbuf[i_buf] == '/' || tmpbuf[i_buf] == ';' ||
+ tmpbuf[i_buf] == 'c') {
+ is_comment = true;
}
}
- } while (bufread==MAXBUFREADLEN);
+ } while (bufread == MAXBUFREADLEN);
ascii_file.close();
- return (new_data);
+ return new_data;
}
More information about the Kst
mailing list