mirror of
https://github.com/Open-Cascade-SAS/OCCT.git
synced 2026-07-10 04:17:44 +08:00
0023850: TDataStd_ByteArray is too slow on storage on disk
Optimization of a byte-array for XML persistence (binary persistence is ok). A possible bug is corrected (size of an array is extended a little). Same improvement for storage of a TDataStd_TreeNode. Improvement of speed of storage of several Ocaf attributes in XML file format. Also, format of storage of a double value is extended to keep 17 digits after a decimal point (it was used only 15 digits before). Several draw-commands are added to manipulate the basic Ocaf attributes: BooleanArray BooleanList IntegerList RealList A test-script for OCAF document successfully saved and opened from disk in XML file format. + 1 is added to keep '\0' Removed several spaces in source files. PLib_LocalArray is renamed to NCollection_LocalArray and became a template. It is used as a local array for Standard_Character in XML OCAF drivers, and as a local array of Standard_Real in PLib package. Small correction of test case for this fix
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <XmlMDataStd_ByteArrayDriver.ixx>
|
||||
#include <TDataStd_ByteArray.hxx>
|
||||
#include <TColStd_HArray1OfByte.hxx>
|
||||
#include <NCollection_LocalArray.hxx>
|
||||
#include <XmlObjMgt.hxx>
|
||||
#include <XmlMDataStd.hxx>
|
||||
|
||||
@@ -93,10 +94,11 @@ Standard_Boolean XmlMDataStd_ByteArrayDriver::Paste(const XmlObjMgt_Persistent&
|
||||
|
||||
|
||||
Handle(TDataStd_ByteArray) aByteArray = Handle(TDataStd_ByteArray)::DownCast(theTarget);
|
||||
Handle(TColStd_HArray1OfByte) array = new TColStd_HArray1OfByte(aFirstInd, aLastInd);
|
||||
Handle(TColStd_HArray1OfByte) hArr = new TColStd_HArray1OfByte(aFirstInd, aLastInd);
|
||||
TColStd_Array1OfByte& arr = hArr->ChangeArray1();
|
||||
|
||||
Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
|
||||
Standard_Integer i = array->Lower(), upper = array->Upper();
|
||||
Standard_Integer i = arr.Lower(), upper = arr.Upper();
|
||||
for (; i <= upper; i++)
|
||||
{
|
||||
if (!XmlObjMgt::GetInteger(aValueStr, aValue))
|
||||
@@ -108,9 +110,9 @@ Standard_Boolean XmlMDataStd_ByteArrayDriver::Paste(const XmlObjMgt_Persistent&
|
||||
WriteMessage (aMessageString);
|
||||
return Standard_False;
|
||||
}
|
||||
array->SetValue(i, (Standard_Byte) aValue);
|
||||
arr.SetValue(i, (Standard_Byte) aValue);
|
||||
}
|
||||
aByteArray->ChangeArray(array);
|
||||
aByteArray->ChangeArray(hArr);
|
||||
|
||||
#ifdef DEB
|
||||
//cout << "CurDocVersion = " << XmlMDataStd::DocumentVersion() <<endl;
|
||||
@@ -152,19 +154,32 @@ void XmlMDataStd_ByteArrayDriver::Paste(const Handle(TDF_Attribute)& theSource,
|
||||
|
||||
Standard_Integer aL = aByteArray->Lower();
|
||||
Standard_Integer anU = aByteArray->Upper();
|
||||
TCollection_AsciiString aValueStr;
|
||||
|
||||
theTarget.Element().setAttribute(::FirstIndexString(), aL);
|
||||
theTarget.Element().setAttribute(::LastIndexString(), anU);
|
||||
theTarget.Element().setAttribute(::IsDeltaOn(),aByteArray->GetDelta());
|
||||
|
||||
const Handle(TColStd_HArray1OfByte)& array = aByteArray->InternalArray();
|
||||
Standard_Integer lower = array->Lower(), i = lower, upper = array->Upper();
|
||||
for (; i <= upper; i++)
|
||||
const Handle(TColStd_HArray1OfByte)& hArr = aByteArray->InternalArray();
|
||||
if (!hArr.IsNull() && hArr->Length())
|
||||
{
|
||||
aValueStr += TCollection_AsciiString((Standard_Integer) array->Value(i));
|
||||
aValueStr += ' ';
|
||||
}
|
||||
XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
|
||||
// Access to data through an internal reprsentation of the array is faster.
|
||||
const TColStd_Array1OfByte& arr = hArr->Array1();
|
||||
|
||||
// Allocate 4 characters (including a space ' ') for each byte (unsigned char) from the array.
|
||||
NCollection_LocalArray<Standard_Character> str(4 * arr.Length() + 1);
|
||||
|
||||
// Char counter in the array of chars.
|
||||
Standard_Integer iChar = 0;
|
||||
|
||||
// Iterate on the array of bytes and fill-in the array of chars inserting spacing between the chars.
|
||||
Standard_Integer iByte = arr.Lower(); // position inside the byte array
|
||||
for (; iByte <= arr.Upper(); ++iByte)
|
||||
{
|
||||
const Standard_Byte& byte = arr.Value(iByte);
|
||||
iChar += Sprintf(&(str[iChar]), "%d ", byte);
|
||||
}
|
||||
|
||||
// Transfer the string (array of chars) to XML.
|
||||
XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user