Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58789 - trunk/libs/regex/example/timer
From: john_at_[hidden]
Date: 2010-01-07 11:47:03


Author: johnmaddock
Date: 2010-01-07 11:47:02 EST (Thu, 07 Jan 2010)
New Revision: 58789
URL: http://svn.boost.org/trac/boost/changeset/58789

Log:
Speed up the code a little, and stop swapping stream buffers around in case that's the cause of some test failures.
Text files modified:
   trunk/libs/regex/example/timer/regex_timer.cpp | 20 ++++++++------------
   1 files changed, 8 insertions(+), 12 deletions(-)

Modified: trunk/libs/regex/example/timer/regex_timer.cpp
==============================================================================
--- trunk/libs/regex/example/timer/regex_timer.cpp (original)
+++ trunk/libs/regex/example/timer/regex_timer.cpp 2010-01-07 11:47:02 EST (Thu, 07 Jan 2010)
@@ -103,6 +103,7 @@
    char c = static_cast<char>(is.get());
    while(c != '\n')
    {
+ BOOST_ASSERT(is.good());
       s.append(1, c);
       c = static_cast<char>(is.get());
    }
@@ -123,16 +124,17 @@
 int main(int argc, char**argv)
 {
    ifstream ifs;
- streambuf* pbuf = 0;
+ std::istream* p_in = &std::cin;
    if(argc == 2)
    {
       ifs.open(argv[1]);
- if(ifs.bad())
+ ifs.peek();
+ if(!ifs.good())
       {
          cout << "Bad filename: " << argv[1] << endl;
          return -1;
       }
- pbuf = cin.rdbuf(ifs.rdbuf());
+ p_in = &ifs;
    }
    
    boost::regex ex;
@@ -152,12 +154,12 @@
    double tim;
    int result = 0;
    unsigned iters = 100;
- double wait_time = (std::min)(t.elapsed_min() * 1000, 1.0);
+ double wait_time = (std::min)(t.elapsed_min() * 1000, 0.5);
 
    while(true)
    {
       cout << "Enter expression (or \"quit\" to exit): ";
- boost::getline(cin, s1);
+ boost::getline(*p_in, s1);
       if(argc == 2)
          cout << endl << s1 << endl;
       if(s1 == "quit")
@@ -191,7 +193,7 @@
       while(true)
       {
          cout << "Enter string to search (or \"quit\" to exit): ";
- boost::getline(cin, s2);
+ boost::getline(*p_in, s2);
          if(argc == 2)
             cout << endl << s2 << endl;
          if(s2 == "quit")
@@ -365,12 +367,6 @@
       regfreeA(&r);
    }
 
- if(pbuf)
- {
- cin.rdbuf(pbuf);
- ifs.close();
- }
-
    return 0;
 }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk