From: nds Date: Sat, 5 Dec 2020 17:12:18 +0000 (+0300) Subject: 0031920: Application Framework - speed up methods of getting label by entry and vise... X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=4e7637c0b66b0a9dc79062b829b2ae7de22e0145;p=occt-copy.git 0031920: Application Framework - speed up methods of getting label by entry and vise versa --- diff --git a/src/TDF/TDF_Tool.cxx b/src/TDF/TDF_Tool.cxx index f587c69603..74f108402f 100644 --- a/src/TDF/TDF_Tool.cxx +++ b/src/TDF/TDF_Tool.cxx @@ -366,6 +366,12 @@ void TDF_Tool::RelocateLabel TDF_Tool::Label(toRoot.Data(),labelTags,aTargetLabel,create); } +static int MyCounter = 0; + +int TDF_Tool::Counter() +{ + return MyCounter; +} //======================================================================= //function : Entry @@ -376,7 +382,8 @@ void TDF_Tool::Entry (const TDF_Label& aLabel, TCollection_AsciiString& anEntry) { - anEntry.Clear(); + MyCounter++; + /*anEntry.Clear(); if (!aLabel.IsNull()) { TColStd_ListOfInteger Tags; TDF_Tool::TagList(aLabel, Tags); @@ -392,10 +399,41 @@ void TDF_Tool::Entry Tags.RemoveFirst(); } } + }*/ + if (!aLabel.IsNull()) { + int aStrLen = 1; // initial "0" of a root label + TDF_Label aLab = aLabel; + for (; !aLab.IsRoot(); aLab = aLab.Father()) + { + for (int aTag = aLab.Tag(); aTag > 9; aTag /= 10) + ++aStrLen; + aStrLen += 2; // one digit and separator + } + if (aStrLen == 1) + { + // an exceptional case for the root label, it ends with separator + static const TCollection_AsciiString THE_ROOT_ENTRY = TCollection_AsciiString('0') + TDF_TagSeparator; + anEntry = THE_ROOT_ENTRY; + } + else + { + anEntry = TCollection_AsciiString(aStrLen, TDF_TagSeparator); + Standard_Character* aPtr = const_cast(anEntry.ToCString() + aStrLen - 1); + for (aLab = aLabel; !aLab.IsRoot(); aLab = aLab.Father()) + { + int aTag = aLab.Tag(); + for (; aTag > 9; --aPtr, aTag /= 10) + *aPtr = Standard_Character(aTag % 10) + '0'; + *aPtr = Standard_Character(aTag) + '0'; + aPtr -= 2; + } + *aPtr = '0'; + } } + else + anEntry.Clear(); } - //======================================================================= //function : TagList //purpose : Returns the entry of a label as a list of integers. diff --git a/src/TDF/TDF_Tool.hxx b/src/TDF/TDF_Tool.hxx index f78245b4db..ad7397b1c3 100644 --- a/src/TDF/TDF_Tool.hxx +++ b/src/TDF/TDF_Tool.hxx @@ -41,6 +41,7 @@ public: DEFINE_STANDARD_ALLOC + Standard_EXPORT static int Counter(); //! Returns the number of labels of the tree, //! including . aLabel is also included in this figure.