Use mmapping when reading Nasal scripts saving two memory copies out of for (copy from disk to the i/o buffer, copy from the i/o buffer tot the ifstream, copy from the ifstreamto a string and copy from a string to Nasal).
This commit is contained in:
parent
d00c95f0e8
commit
098300bb51
1 changed files with 11 additions and 0 deletions
|
@ -47,6 +47,7 @@
|
||||||
#include <simgear/props/props.hxx>
|
#include <simgear/props/props.hxx>
|
||||||
#include <simgear/structure/commands.hxx>
|
#include <simgear/structure/commands.hxx>
|
||||||
#include <simgear/structure/event_mgr.hxx>
|
#include <simgear/structure/event_mgr.hxx>
|
||||||
|
#include <simgear/io/sg_mmap.hxx>
|
||||||
|
|
||||||
#include <simgear/nasal/cppbind/from_nasal.hxx>
|
#include <simgear/nasal/cppbind/from_nasal.hxx>
|
||||||
#include <simgear/nasal/cppbind/to_nasal.hxx>
|
#include <simgear/nasal/cppbind/to_nasal.hxx>
|
||||||
|
@ -1505,6 +1506,15 @@ bool FGNasalSys::loadModule(SGPath file, const char* module)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
// MMap the contents of the file.
|
||||||
|
// This saves an alloc, memcpy and free
|
||||||
|
SGMMapFile mmap(file);
|
||||||
|
mmap.open(SG_IO_IN);
|
||||||
|
|
||||||
|
auto pathStr = file.utf8Str();
|
||||||
|
return createModule(module, pathStr.c_str(), mmap.get(), mmap.get_size());
|
||||||
|
#else
|
||||||
sg_ifstream file_in(file);
|
sg_ifstream file_in(file);
|
||||||
string buf;
|
string buf;
|
||||||
while (!file_in.eof()) {
|
while (!file_in.eof()) {
|
||||||
|
@ -1515,6 +1525,7 @@ bool FGNasalSys::loadModule(SGPath file, const char* module)
|
||||||
file_in.close();
|
file_in.close();
|
||||||
auto pathStr = file.utf8Str();
|
auto pathStr = file.utf8Str();
|
||||||
return createModule(module, pathStr.c_str(), buf.data(), buf.length());
|
return createModule(module, pathStr.c_str(), buf.data(), buf.length());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse and run. Save the local variables namespace, as it will
|
// Parse and run. Save the local variables namespace, as it will
|
||||||
|
|
Loading…
Reference in a new issue