Skip to content

Commit a6ba1ab

Browse files
committed
Fix performance regression in 62119e5.
That commit caused unnecessary creation of string objects in REGEX commands. Work around that by providing direct access to the data buffer. Also use peek() instead of next() to not construct unnecessary single-char string objects. Addresses #8.
1 parent 42edb06 commit a6ba1ab

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

databuffer.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class databuffer {
3030
size_t line() const { return _line; }
3131
size_t lpos() const { return _lpos; }
3232

33+
std::string::const_iterator curr() const { return data.cbegin()+_pos; }
34+
std::string::const_iterator begin() const { return data.cbegin(); }
35+
std::string::const_iterator end() const { return data.cend(); }
36+
3337
std::string next(size_t length=1) const
3438
{
3539
size_t end = std::min(size(),_pos+length);

libchecktestdata.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ bool dotest(const test& t)
602602
if ( gendata ) {
603603
return (get_random(2) == 0);
604604
} else {
605-
return !data.eof() && t.args[0].val.find(data.next())!=string::npos;
605+
return !data.eof() && t.args[0].val.find(data.peek())!=string::npos;
606606
}
607607
case 'U': return unique(t.args);
608608
case 'A': return inarray(t.args[0],t.args[1]);
@@ -1010,8 +1010,9 @@ void checktoken(const command& cmd)
10101010
if ( toupper(data.readchar())!='E' ) error("exponent 'E' expected");
10111011
has_exp = true;
10121012
if ( data.peek()=='-' || data.peek()=='+' ) data.readchar();
1013-
while ( isdigit(data.peek()) ) data.readchar();
1014-
if ( !isdigit(data.peek(-1)) ) error("digit expected");
1013+
char c = '!';
1014+
while ( isdigit(data.peek()) ) c = data.readchar();
1015+
if ( !isdigit(c) ) error("digit expected");
10151016
}
10161017

10171018
if ( cmd.name()=="FLOATP" ) {
@@ -1055,8 +1056,8 @@ void checktoken(const command& cmd)
10551056
smatch res;
10561057
string matchstr;
10571058

1058-
string searchstr = data.next(data.size());
1059-
if ( !regex_search(searchstr,res,regexstr,regex_constants::match_continuous) ) {
1059+
if ( !regex_search(data.curr(),data.end(),res,regexstr,
1060+
regex_constants::match_continuous) ) {
10601061
error();
10611062
} else {
10621063
size_t match_len = res[0].second - res[0].first;

0 commit comments

Comments
 (0)