aboutsummaryrefslogtreecommitdiff
path: root/unit-tests/cc
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-07-24 14:08:26 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-07-24 14:09:08 +0200
commit875c6e81e5ed52df46740083451380c4597b560c (patch)
treec3df90087a7797575a6343fb0fe6bc4444975cb5 /unit-tests/cc
parentc18a8d2d43f22ccf0b21461b1f0d3395d4e50c1f (diff)
Optimize C/C++ lexer
Diffstat (limited to 'unit-tests/cc')
-rw-r--r--unit-tests/cc/lexer/driver.cxx17
-rw-r--r--unit-tests/cc/parser/driver.cxx20
2 files changed, 13 insertions, 24 deletions
diff --git a/unit-tests/cc/lexer/driver.cxx b/unit-tests/cc/lexer/driver.cxx
index 5803a88..53910a6 100644
--- a/unit-tests/cc/lexer/driver.cxx
+++ b/unit-tests/cc/lexer/driver.cxx
@@ -11,6 +11,7 @@
#include <build2/cc/lexer.hxx>
using namespace std;
+using namespace butl;
namespace build2
{
@@ -39,24 +40,16 @@ namespace build2
try
{
- istream* is;
-
- // Reading from file is several times faster.
- //
- ifdstream ifs;
+ ifdstream is;
if (file != nullptr)
- {
- ifs.open (file);
- is = &ifs;
- }
+ is.open (file);
else
{
file = "stdin";
- cin.exceptions (istream::failbit | istream::badbit);
- is = &cin;
+ is.open (fddup (stdin_fd ()));
}
- lexer l (*is, path (file));
+ lexer l (is, path (file));
// No use printing eos since we will either get it or loop forever.
//
diff --git a/unit-tests/cc/parser/driver.cxx b/unit-tests/cc/parser/driver.cxx
index ec346d3..19d85e8 100644
--- a/unit-tests/cc/parser/driver.cxx
+++ b/unit-tests/cc/parser/driver.cxx
@@ -11,6 +11,7 @@
#include <build2/cc/parser.hxx>
using namespace std;
+using namespace butl;
namespace build2
{
@@ -23,27 +24,22 @@ namespace build2
{
try
{
- istream* is;
- const char* in;
+ const char* file;
- // Reading from file is several times faster.
- //
- ifdstream ifs;
+ ifdstream is;
if (argc > 1)
{
- in = argv[1];
- ifs.open (in);
- is = &ifs;
+ file = argv[1];
+ is.open (file);
}
else
{
- in = "stdin";
- cin.exceptions (istream::failbit | istream::badbit);
- is = &cin;
+ file = "stdin";
+ is.open (fddup (stdin_fd ()));
}
parser p;
- translation_unit u (p.parse (*is, path (in)));
+ translation_unit u (p.parse (is, path (file)));
for (const module_import& m: u.mod.imports)
cout << (m.exported ? "export " : "")