From ff97747bb701875c93f60c70049f3b92e75f6523 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Tue, 25 Apr 2023 22:19:16 +0800 Subject: [PATCH] App: renable StringHasher IndexedName optimization The benifit of StringHasher optimization for IndexedName is most evident on boolean operation of primitive/dumb shape array, e.g. those imported from STEP, because those shape elements are not encoded, henced mapped in as plain IndexedName. The optimization split the integer from the IndexedName to only store the type name to reduce redundancy. --- src/App/StringHasher.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/App/StringHasher.cpp b/src/App/StringHasher.cpp index d116bf0ab9..f4d0f94cb4 100644 --- a/src/App/StringHasher.cpp +++ b/src/App/StringHasher.cpp @@ -304,9 +304,9 @@ StringIDRef StringHasher::getID(const Data::MappedName& name, const QVector 0) {// If the data had an index + if (res.index != 0) { + indexed.setIndex(res.index); + newStringID._data.resize(newStringID._data.lastIndexOf(':')+1); + } int offset = newStringID.isPostfixEncoded() ? 1 : 0; // Search for the SID with that index for (int i = offset; i < newStringID._sids.size(); ++i) { @@ -579,10 +583,7 @@ void StringHasher::saveStream(std::ostream& stream) const // guarantees to be a single line without space. So it is safe to // store in raw stream. if (d.isPostfixed()) { - if (d.isPrefixIDIndex()) { - stream << ' ' << prefixID.index; - } - else if (!d.isIndexed() && !d.isPrefixID()) { + if (!d.isPrefixIDIndex() && !d.isIndexed() && !d.isPrefixID()) { stream << ' ' << d._data.constData(); } @@ -714,13 +715,9 @@ void StringHasher::restoreStreamNew(std::istream& stream, std::size_t count) if (d._sids.size() <= offset) { FC_THROWM(Base::RuntimeError, "Missing string prefix id"); } - int index = 0; - if (d.isPrefixIDIndex()) { - if (!(stream >> index)) { - FC_THROWM(Base::RuntimeError, "Missing string prefix index"); - } - } - d._data = d._sids[offset]._sid->toString(index).c_str(); + d._data = d._sids[offset]._sid->toString(0).c_str(); + if (d.isPrefixIDIndex()) + d._data += ":"; } else { stream >> content;