From 703f1840af79ca4480c664190cdcf7e6fbd7b90e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 28 Dec 2010 23:46:45 +0000 Subject: Avoid string copy (store const char* for command line filenames instead of std::string). git-svn-id: http://svn.drobilla.net/resp/resp@368 ad02d1e2-f140-0410-9f75-f8b11f17cedd --- src/resp.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/resp.cpp b/src/resp.cpp index b264850..66847fd 100644 --- a/src/resp.cpp +++ b/src/resp.cpp @@ -37,7 +37,7 @@ bool is_form(const AST* ast, const std::string& form) { const ATuple* call = ast->to_tuple(); - if (!call) + if (!call || call->empty()) return false; const ASymbol* const sym = call->fst()->to_symbol(); @@ -89,7 +89,8 @@ main(int argc, char** argv) { // Read command line arguments map args; - list files; + typedef list Files; + Files files; for (int i = 1; i < argc; ++i) { if (!strncmp(argv[i], "-h", 3)) { return print_usage(argv[0], false); @@ -148,8 +149,8 @@ main(int argc, char** argv) fs.open(output.c_str()); ostream& os = (output == "") ? std::cout : fs; - for (list::iterator f = files.begin(); f != files.end(); ++f) { - ifstream is(f->c_str()); + for (Files::iterator f = files.begin(); f != files.end(); ++f) { + ifstream is(*f); try { while (is.good() && !is.eof()) { Cursor loc(*f); @@ -183,14 +184,14 @@ main(int argc, char** argv) ret = repl(*cenv); } else { // Evalute (or just type check if -T, or just compile if -S all files - for (list::iterator f = files.begin(); f != files.end(); ++f) { - const string& filename = *f; + for (Files::iterator f = files.begin(); f != files.end(); ++f) { + const string filename = *f; if (!batch) output = filename + ".out"; - ifstream is(f->c_str()); + ifstream is(*f); if (is.good()) { - Cursor cursor(*f); + Cursor cursor(filename); ret = ret | eval(*cenv, cursor, is, !batch); } else { cerr << argv[0] << ": " << *f << ": " << strerror(errno) << endl; -- cgit v1.2.1