[Libreoffice-commits] online.git: wsd/TraceFile.hpp
Jan Holesovsky
kendy at collabora.com
Mon Feb 6 12:44:08 UTC 2017
wsd/TraceFile.hpp | 54 +++++++++++++++++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 21 deletions(-)
New commits:
commit 898b5d9e4c43850d6326abefdba0e0bcf6bb1123
Author: Jan Holesovsky <kendy at collabora.com>
Date: Mon Feb 6 13:36:54 2017 +0100
Treat the rest of the line as payload, because it may contain the delimiter.
Change-Id: I883f41727cf46c4b71484d2b99144ae7e30ef6d3
diff --git a/wsd/TraceFile.hpp b/wsd/TraceFile.hpp
index 347e5f6..8f308f1 100644
--- a/wsd/TraceFile.hpp
+++ b/wsd/TraceFile.hpp
@@ -378,22 +378,11 @@ private:
break;
}
- const auto v = split(line, line[0]);
- if (v.size() == 4)
- {
- TraceFileRecord rec;
- rec.Dir = static_cast<TraceFileRecord::Direction>(line[0]);
- unsigned index = 0;
- rec.TimestampNs = std::atoi(v[index++].c_str());
- rec.Pid = std::atoi(v[index++].c_str());
- rec.SessionId = v[index++];
- rec.Payload = v[index++];
+ TraceFileRecord rec;
+ if (extractRecord(line, rec))
_records.push_back(rec);
- }
else
- {
fprintf(stderr, "Invalid trace file record, expected 4 tokens. [%s]\n", line.c_str());
- }
}
if (_records.empty() ||
@@ -411,20 +400,43 @@ private:
_epochStart = _records[0].TimestampNs;
}
- static std::vector<std::string> split(const std::string& s, const char delim)
+ static bool extractRecord(const std::string& s, TraceFileRecord& rec)
{
- std::stringstream ss(s);
- std::string item;
- std::vector<std::string> v;
- while (std::getline(ss, item, delim))
+ if (s.length() < 1)
+ return false;
+
+ char delimiter = s[0];
+ rec.Dir = static_cast<TraceFileRecord::Direction>(delimiter);
+
+ size_t pos = 1;
+ int record = 0;
+ for (; record < 4 && pos < s.length(); ++record)
{
- if (!item.empty())
+ size_t next = s.find(delimiter, pos);
+
+ switch (record)
{
- v.push_back(item);
+ case 0:
+ rec.TimestampNs = std::atoi(s.substr(pos, next - pos).c_str());
+ break;
+ case 1:
+ rec.Pid = std::atoi(s.substr(pos, next - pos).c_str());
+ break;
+ case 2:
+ rec.SessionId = s.substr(pos, next - pos);
+ break;
+ case 3:
+ rec.Payload = s.substr(pos);
+ return true;
}
+
+ if (next == std::string::npos)
+ break;
+
+ pos = next + 1;
}
- return v;
+ return false;
}
unsigned advance(unsigned index, const TraceFileRecord::Direction dir)
More information about the Libreoffice-commits
mailing list