wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp seria...


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src filesystem.cpp filesystem.hpp seria...
Date: Fri, 25 Mar 2005 11:10:09 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    05/03/25 16:10:09

Modified files:
        src            : filesystem.cpp filesystem.hpp 
        src/serialization: preprocessor.cpp 

Log message:
        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).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.cpp.diff?tr1=1.60&tr2=1.61&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/filesystem.hpp.diff?tr1=1.32&tr2=1.33&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/preprocessor.cpp.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: wesnoth/src/filesystem.cpp
diff -u wesnoth/src/filesystem.cpp:1.60 wesnoth/src/filesystem.cpp:1.61
--- wesnoth/src/filesystem.cpp:1.60     Sun Feb 20 00:31:49 2005
+++ wesnoth/src/filesystem.cpp  Fri Mar 25 16:10:08 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.cpp,v 1.60 2005/02/20 00:31:49 ydirson Exp $ */
+/* $Id: filesystem.cpp,v 1.61 2005/03/25 16:10:08 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -489,6 +489,30 @@
        }
 }
 
+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)
 {
Index: wesnoth/src/filesystem.hpp
diff -u wesnoth/src/filesystem.hpp:1.32 wesnoth/src/filesystem.hpp:1.33
--- wesnoth/src/filesystem.hpp:1.32     Sun Feb 20 17:56:14 2005
+++ wesnoth/src/filesystem.hpp  Fri Mar 25 16:10:08 2005
@@ -1,4 +1,4 @@
-/* $Id: filesystem.hpp,v 1.32 2005/02/20 17:56:14 silene Exp $ */
+/* $Id: filesystem.hpp,v 1.33 2005/03/25 16:10:08 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -58,6 +58,7 @@
 //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();
Index: wesnoth/src/serialization/preprocessor.cpp
diff -u wesnoth/src/serialization/preprocessor.cpp:1.2 
wesnoth/src/serialization/preprocessor.cpp:1.3
--- wesnoth/src/serialization/preprocessor.cpp:1.2      Sat Mar  5 10:54:25 2005
+++ wesnoth/src/serialization/preprocessor.cpp  Fri Mar 25 16:10:09 2005
@@ -1,4 +1,4 @@
-/* $Id: preprocessor.cpp,v 1.2 2005/03/05 10:54:25 silene Exp $ */
+/* $Id: preprocessor.cpp,v 1.3 2005/03/25 16:10:09 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -15,9 +15,7 @@
 #include "global.hpp"
 
 #include <algorithm>
-#include <fstream>
 #include <iostream>
-#include <stack>
 #include <sstream>
 #include <vector>
 
@@ -92,12 +90,22 @@
                               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 @@
                                        }
                                }
 
-                               
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 @@
                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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]