Toward a faster and cheaper WML.
First step: sanitize the interfaces so as to not require the whole files to be in memory (only the interfaces, the implementations still require it at the moment).
This commit is contained in:
parent
613b4aa37f
commit
66b50d098a
3 changed files with 41 additions and 5 deletions
|
@ -489,6 +489,30 @@ std::string read_file(const std::string& fname)
|
|||
}
|
||||
}
|
||||
|
||||
std::istream *stream_file(std::string const &fname)
|
||||
{
|
||||
LOG_G << "Streaming " << fname << "\n";
|
||||
#ifdef USE_ZIPIOS
|
||||
if (!fname.empty() && fname[0] != '/') {
|
||||
zipios::ConstEntryPointer p = the_collection->getEntry(fname);
|
||||
if (p != 0)
|
||||
if (std::istream *s = the_collection->getInputStream(p))
|
||||
return s;
|
||||
}
|
||||
#else
|
||||
if (!fname.empty() && fname[0] != '/' && !game_config::path.empty()) {
|
||||
std::ifstream *s = new ifstream((game_config::path + "/" + fname).c_str());
|
||||
if (s->is_open())
|
||||
return s;
|
||||
delete s;
|
||||
}
|
||||
#endif
|
||||
|
||||
// FIXME: why do we rely on this even with relative paths ?
|
||||
// still useful with zipios, for things like cache and prefs
|
||||
return new std::ifstream(fname.c_str());
|
||||
}
|
||||
|
||||
//throws io_exception if an error occurs
|
||||
void write_file(const std::string& fname, const std::string& data)
|
||||
{
|
||||
|
|
|
@ -58,6 +58,7 @@ void make_directory(const std::string& dirname);
|
|||
//basic disk I/O
|
||||
bool filesystem_init();
|
||||
std::string read_file(const std::string& fname);
|
||||
std::istream *stream_file(std::string const &fname);
|
||||
//throws io_exception if an error occurs
|
||||
void write_file(const std::string& fname, const std::string& data);
|
||||
std::string read_stdin();
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
#include "global.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <stack>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
@ -92,12 +90,22 @@ void internal_preprocess_file(const std::string& fname,
|
|||
int depth, std::vector<char>& res,
|
||||
std::vector<line_source>* lines_src, int& line);
|
||||
|
||||
void internal_preprocess_data(const std::string& data,
|
||||
void internal_preprocess_data(std::istream &data_in,
|
||||
preproc_map& defines_map,
|
||||
int depth, std::vector<char>& res,
|
||||
std::vector<line_source>* lines_src, int& line,
|
||||
const std::string& fname, int srcline)
|
||||
{
|
||||
|
||||
std::string data_str;
|
||||
{
|
||||
//temporary, only here to accomodate the old preprocessor
|
||||
std::stringstream tmp_in;
|
||||
tmp_in << data_in.rdbuf();
|
||||
data_str = tmp_in.str();
|
||||
}
|
||||
std::string const &data = data_str;
|
||||
|
||||
bool in_quotes = false;
|
||||
|
||||
for(std::string::const_iterator i = data.begin(); i != data.end(); ++i) {
|
||||
|
@ -165,7 +173,8 @@ void internal_preprocess_data(const std::string& data,
|
|||
}
|
||||
}
|
||||
|
||||
internal_preprocess_data(str,defines_map,depth,res,NULL,line,fname,srcline);
|
||||
std::istringstream stream(str);
|
||||
internal_preprocess_data(stream, defines_map, depth, res, NULL, line, fname, srcline);
|
||||
} else if(depth < 20) {
|
||||
std::string prefix;
|
||||
std::string nfname;
|
||||
|
@ -373,7 +382,9 @@ void internal_preprocess_file(const std::string& fname,
|
|||
lines_src->push_back(line_source(line,fname,1));
|
||||
}
|
||||
|
||||
internal_preprocess_data(read_file(fname),defines_map,depth,res,lines_src,line,fname,1);
|
||||
std::istream *s = stream_file(fname);
|
||||
internal_preprocess_data(*s, defines_map, depth, res, lines_src, line, fname, 1);
|
||||
delete s;
|
||||
}
|
||||
|
||||
} //end anonymous namespace
|
||||
|
|
Loading…
Add table
Reference in a new issue