Insignificantly speed up opening UTF-8 files

This commit is contained in:
Thomas Goyne 2013-06-09 07:56:20 -07:00
parent 2a2a623bb4
commit 9133f17e82
1 changed files with 10 additions and 9 deletions

View File

@ -67,18 +67,19 @@ public:
: stream(&stream) : stream(&stream)
, valid(true) , valid(true)
, encoding(encoding) , encoding(encoding)
, cr(0) , cr('\r')
, lf(0) , lf('\n')
, width(0) , width(1)
{ {
boost::to_lower(encoding); boost::to_lower(encoding);
if (encoding != "utf-8") {
agi::charset::IconvWrapper c("utf-8", encoding.c_str()); agi::charset::IconvWrapper c("utf-8", encoding.c_str());
c.Convert("\r", 1, reinterpret_cast<char *>(&cr), sizeof(int)); c.Convert("\r", 1, reinterpret_cast<char *>(&cr), sizeof(int));
c.Convert("\n", 1, reinterpret_cast<char *>(&lf), sizeof(int)); c.Convert("\n", 1, reinterpret_cast<char *>(&lf), sizeof(int));
width = c.RequiredBufferSize("\n"); width = c.RequiredBufferSize("\n");
conv = std::make_shared<agi::charset::IconvWrapper>(encoding.c_str(), "utf-8");
}
if (encoding != "utf-8")
conv.reset(new agi::charset::IconvWrapper(encoding.c_str(), "utf-8"));
init(); init();
++(*this); ++(*this);
} }