Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2011-11-25 00:28:17 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:28:44 +0300
commit65530f86918698ec5cc6dbdd408e6295c28f7c1a (patch)
tree2b95e76f79c16a60b38e0b1a95ac72bebadfba8f /indexer/classificator_loader.cpp
parentc11367ac7accbbff694befc754132c3da8b76540 (diff)
Avoid overhead in classificator reading (read to string -> istringstream).
Add reading of binary proto drawing rules.
Diffstat (limited to 'indexer/classificator_loader.cpp')
-rw-r--r--indexer/classificator_loader.cpp82
1 files changed, 58 insertions, 24 deletions
diff --git a/indexer/classificator_loader.cpp b/indexer/classificator_loader.cpp
index bec3a794fc..5ad83f25e3 100644
--- a/indexer/classificator_loader.cpp
+++ b/indexer/classificator_loader.cpp
@@ -4,41 +4,51 @@
#include "../../platform/platform.hpp"
-#include "../coding/file_reader_stream.hpp"
-#include "../coding/file_reader.hpp"
+#include "../coding/reader_streambuf.hpp"
#include "../base/logging.hpp"
+#include "../std/fstream.hpp"
+
namespace classificator
{
- void ReadCommon(ReaderType const & classificator,
- ReaderType const & visibility,
- ReaderType const & types)
+ void ReadCommon(Reader * classificator,
+ Reader * visibility,
+ Reader * types)
{
- string buffer;
-
Classificator & c = classif();
c.Clear();
- //LOG(LINFO, ("Reading classificator"));
- classificator.ReadAsString(buffer);
- c.ReadClassificator(buffer);
+ {
+ //LOG(LINFO, ("Reading classificator"));
+ ReaderStreamBuf buffer(classificator);
+
+ istream s(&buffer);
+ c.ReadClassificator(s);
+ }
- //LOG(LINFO, ("Reading visibility"));
- visibility.ReadAsString(buffer);
- c.ReadVisibility(buffer);
+ {
+ //LOG(LINFO, ("Reading visibility"));
+ ReaderStreamBuf buffer(visibility);
- //LOG(LINFO, ("Reading types mapping"));
- types.ReadAsString(buffer);
- c.ReadTypesMapping(buffer);
+ istream s(&buffer);
+ c.ReadVisibility(s);
+ }
+
+ {
+ //LOG(LINFO, ("Reading types mapping"));
+ ReaderStreamBuf buffer(types);
+
+ istream s(&buffer);
+ c.ReadTypesMapping(s);
+ }
}
void ReadVisibility(string const & fPath)
{
- string buffer;
- ReaderType(new FileReader(fPath)).ReadAsString(buffer);
- classif().ReadVisibility(buffer);
+ ifstream s(fPath.c_str());
+ classif().ReadVisibility(s);
}
void Load()
@@ -52,11 +62,35 @@ namespace classificator
p.GetReader("types.txt"));
//LOG(LINFO, ("Reading of drawing rules"));
-
- // Load from protobuffer text file.
- string buffer;
- ReaderType(p.GetReader("drules_proto.txt")).ReadAsString(buffer);
- drule::rules().LoadFromTextProto(buffer);
+ drule::RulesHolder & rules = drule::rules();
+
+ try
+ {
+ // Load from protobuffer binary file.
+ ReaderStreamBuf buffer(p.GetReader("drules_proto.bin"));
+
+ istream s(&buffer);
+ rules.LoadFromBinaryProto(s);
+ }
+ catch (Reader::OpenException const &)
+ {
+ try
+ {
+ // Load from protobuffer text file.
+ string buffer;
+ ModelReaderPtr(p.GetReader("drules_proto.txt")).ReadAsString(buffer);
+
+ rules.LoadFromTextProto(buffer);
+
+ // Uncomment this to save actual drawing rules to binary proto format.
+ //ofstream s(p.WritablePathForFile("drules_proto.bin").c_str(), ios::out | ios::binary);
+ //rules.SaveToBinaryProto(buffer, s);
+ }
+ catch (Reader::OpenException const &)
+ {
+ LOG(LERROR, ("No drawing rules found"));
+ }
+ }
LOG(LINFO, ("Reading of classificator finished"));
}