mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0029399: Optimize reading of floating point values from text strings
Function Strtod() is reimplemented using open source (MIT-style license) code by David M. Gay instead of strtod() provided by standard run-time library. This improves its performance by 3-10 times. Functions Atof(), Strtod(), Printf(), Sprintf(), Fprintf() are declared as extern "C" to be usable from C programs. Strtod() is used in Interface_FileReaderData::Fastof() and in RWStl_Reader to accelerate their work. DRAW command QATestAtof and test perf fclasses strtod are added to check correctness and performance of Strtod(). Test perf draw restore is added to monitor performance of reading BREP files. Minor off-topic corrections: - method Standard_GUID::Assign (const Standard_UUID&) is implemented (was empty); - Precision.hxx is included in BRepMesh_Vertex.hxx that uses it.
This commit is contained in:
@@ -235,6 +235,23 @@ static inline bool str_starts_with (const char* theStr, const char* theWord, int
|
||||
return !strncmp (theStr, theWord, theN);
|
||||
}
|
||||
|
||||
static bool ReadVertex (const char* theStr, double& theX, double& theY, double& theZ)
|
||||
{
|
||||
const char *aStr = theStr;
|
||||
|
||||
// skip 'vertex'
|
||||
while (isspace ((unsigned char)*aStr) || isalpha ((unsigned char)*aStr))
|
||||
++aStr;
|
||||
|
||||
// read values
|
||||
char *aEnd;
|
||||
theX = Strtod (aStr, &aEnd);
|
||||
theY = Strtod (aStr = aEnd, &aEnd);
|
||||
theZ = Strtod (aStr = aEnd, &aEnd);
|
||||
|
||||
return aEnd != aStr;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
//function : ReadAscii
|
||||
//purpose :
|
||||
@@ -314,11 +331,9 @@ Standard_Boolean RWStl_Reader::ReadAscii (Standard_IStream& theStream,
|
||||
aNbLine += 5;
|
||||
|
||||
Standard_Real x1, y1, z1, x2, y2, z2, x3, y3, z3;
|
||||
Standard_Integer aReadCount = // read 3 lines "vertex x y z"
|
||||
sscanf_l (aLine1, aLocale, "%*s %lf %lf %lf", &x1, &y1, &z1) +
|
||||
sscanf_l (aLine2, aLocale, "%*s %lf %lf %lf", &x2, &y2, &z2) +
|
||||
sscanf_l (aLine3, aLocale, "%*s %lf %lf %lf", &x3, &y3, &z3);
|
||||
if (aReadCount != 9)
|
||||
if (! ReadVertex (aLine1, x1, y1, z1) ||
|
||||
! ReadVertex (aLine2, x2, y2, z2) ||
|
||||
! ReadVertex (aLine3, x3, y3, z3))
|
||||
{
|
||||
TCollection_AsciiString aStr ("Error: cannot read vertex co-ordinates at line ");
|
||||
aStr += aNbLine;
|
||||
|
Reference in New Issue
Block a user