Commit Graph

47 Commits

Author SHA1 Message Date
Florian Foinant-Willig
756e3789ce Fix FreeCAD#19588 2025-03-20 20:14:50 +01:00
Kevin Martin
edb8e4c937 Address performance of existing unique-name generation (Part 2) (#18676)
As described in Issue 16849, the existing Tools::getUniqueName method
requires calling code to form a vector of existing names to be avoided.

This leads to poor performance both in the O(n) cost of building such a
vector and also getUniqueName's O(n) algorithm for actually generating
the unique name (where 'n' is the number of pre-existing names).

This has  particularly noticeable cost in documents with large numbers
of DocumentObjects because generating both Names and Labels for each new
object incurs this cost. During an operation such as importing this
results in an O(n^2) time spent generating names.

The other major cost is in the saving of the temporary backup file,
which uses name generation for the "files" embedded in the Zip file.
Documents can easily need several such "files" for each object in the
document.

This update includes the following changes to use the newly-added
UniqueNameManager as a replacement for the old Tools::getUniqueName
method and deletes the latter to remove any temptation to use it as
its usage model breeds inefficiency:

Eliminate Tools::getUniqueName, its local functions, and its unit tests.

Make DocumentObject naming use the new UniqueNameManager class.

Make DocumentObject Label naming use the new UniqueNameManager class.
This needs to monitor DocumentObject Labels for changes since this
property is not read-only. The special handling for the Label
property, which includes optionally forcing uniqueness and updating
links in referencing objects, has been mostly moved from
PropertyString to DocumentObject.

Add Document::containsObject(DocumentObject*) for a definitive
test of an object being in a Document. This is needed because
DocumentObjects can be in a sort of limbo (e.g. when they are in the
Undo/Redo lists) where they have a parent linkage to the Document but
should not participate in Label collision checks.

Rename Document.getStandardObjectName to getStandardObjectLabel
to better represent what it does.

Use new UniqueNameManager for Writer internal filenames within the zip
file.

Eliminate unneeded Reader::FileNames collection. The file names
already exist in the FileList collection elements. The only existing
use for the FileNames collection was to determine if there were any
files at all, and with FileList and FileNames being parallel
vectors, they both had the same length so FileList could be used
for this test..

Use UniqueNameManager for document names and labels. This uses ad hoc
UniqueNameManager objects created on the spot on the assumption that
document creation is relatively rare and there are few documents, so
although the cost is O(n), n itself is small.

Use an ad hoc UniqueNameManager to name new DymanicProperty entries.
This is only done if a property of the proposed name already exists,
since such a check is more-or-less O(log(n)), almost never finds a
collision, and avoids the O(n) building of the UniqueNameManager.
If there is a collision an ad-hoc UniqueNameManager is built
and discarded after use.
The property management classes have a bit of a mess of methods
including several to populate various collection types with all
existing properties. Rather than introducing yet another such
collection-specific method to fill a UniqueNameManager, a
visitProperties method was added which calls a passed function for
each property. The existing code (e.g. getPropertyMap) would be
simpler if they all used this but the cost of calling a lambda
for each property must be considered. It would clarify the semantics
of these methods, which have a bit of variance in which properties
populate the passed collection, e.g. when there are duplicate names..
Ideally the PropertyContainer class would keep a central directory of
all properties ("static", Dynamic, and exposed by ExtensionContainer and
other derivations) and a permanent UniqueNameManager. However the
Property management is a bit of a mess making such a change a project
unto itself.
2025-02-24 10:23:53 -06:00
Benjamin Bræstrup Sayoc
6f619b5f1c Base: remove unneeded includes 2025-02-18 11:07:57 -06:00
Benjamin Nauck
39402e2083 Revert "Address the poor performance of the existing unique-name generation (#17944)"
This reverts commit 83202d8ad6.

# Conflicts:
#	src/Base/Tools.cpp
#	src/Base/Tools.h
2024-12-16 17:31:43 +01:00
Kevin Martin
5696c9add3 Address the poor performance of the existing unique-name generation (#17944)
* Address the poor performance of the existing unique-name generation

As described in Issue 16849, the existing Tools::getUniqueName method
requires calling code to form a vector of existing names to be avoided.

This leads to poor performance both in the O(n) cost of building such a
vector and also getUniqueName's O(n) algorithm for actually generating
the unique name (where 'n' is the number of pre-existing names).

This has  particularly noticeable cost in documents with large numbers
of DocumentObjects because generating both Names and Labels for each new
object incurs this cost. During an operation such as importing this
results in an O(n^2) time spent generating names.

The other major cost is in the saving of the temporary backup file,
which uses name generation for the "files" embedded in the Zip file.
Documents can easily need several such "files" for each object in the
document.

This update includes the following changes:

Create UniqueNameManager to keep a list of existing names organized in
a manner that eases unique-name generation. This class essentially acts
as a set of names, with the ability to add and remove names and check if
a name is already there, with the added ability to take a prototype name
and generate a unique form for it which is not already in the set.

Eliminate Tools::getUniqueName

Make DocumentObject naming use the new UniqueNameManager class

Make DocumentObject Label naming use the new UniqueNameManager class.
Labels are not always unique; unique labels are generated if the
settings at the time request it (and other conditions). Because of this
the Label management requires additionally keeping a map of counts
for labels which already exist more than once.
These collections are maintained via notifications of value changes on
the Label properties of the objects in the document.

Add Document::containsObject(DocumentObject*) for a definitive
test of an object being in a Document. This is needed because
DocumentObjects can be in a sort of limbo (e.g. when they are in the
Undo/Redo lists) where they have a parent linkage to the Document but
should not participate in Label collision checks.

Rename Document.getStandardObjectName to getStandardObjectLabel
to better represent what it does.

Use new UniqueNameManager for Writer internal filenames within the zip
file.

Eliminate unneeded Reader::FileNames collection. The file names
already exist in the FileList collection elements. The only existing
use for the FileNames collection was to determine if there were any
files at all, and with FileList and FileNames being parallel
vectors, they both had the same length so FileList could be used
for this test..

Use UniqueNameManager for document names and labels. This uses ad hoc
UniqueNameManager objects created on the spot on the assumption that
document creation is relatively rare and there are few documents, so
although the cost is O(n), n itself is small.

Use an ad hoc UniqueNameManager to name new DymanicProperty entries.
This is only done if a property of the proposed name already exists,
since such a check is more-or-less O(log(n)), almost never finds a
collision, and avoids the O(n) building of the UniqueNameManager.
If there is a collision an ad-hoc UniqueNameManager is built
and discarded after use.
The property management classes have a bit of a mess of methods
including several to populate various collection types with all
existing properties. Rather than introducing yet another such
collection-specific method to fill a UniqueNameManager, a
visitProperties method was added which calls a passed function for
each property. The existing code would be simpler if existing
fill-container methods all used this.
Ideally the PropertyContainer class would keep a central directory of
all properties ("static", Dynamic, and exposed by ExtensionContainer and
other derivations) and a permanent UniqueNameManager. However the
Property management is a bit of a mess making such a change a project
unto itself.

The unit tests for Tools:getUniqueName have been changed to test
UniqueNameManager.makeUniqueName instead.
This revealed a small regression insofar as passing a prototype name
like "xyz1234" to the old code would yield "xyz1235" whether or
not "xyz1234" already existed, while the new code will return the next
name above the currently-highest name on the "xyz" model, which could
be "xyz" or "xyz1".

* Correct wrong case on include path

* Implement suggested code changes
Also change the semantics of visitProperties to not have any short-circuit return

* Remove reference through undefined iterator

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix up some comments for DOxygen

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-12-13 10:54:46 -06:00
pre-commit-ci[bot]
2b018b20ce [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-06-24 03:34:21 +00:00
bgbsww
aa66518568 Toponaming: Fix save and restore of elementmaps 2024-06-23 23:33:12 -04:00
wmayer
a6ea6ff155 fix readability-make-member-function-const 2023-11-16 01:22:09 +01:00
wmayer
276bbcad6e fix readability-*:
* readability-uppercase-literal-suffix
* readability-named-parameter
2023-11-16 01:22:08 +01:00
wmayer
bd88162b9d fix readability-*:
* readability-const-return-type
* readability-container-data-pointer
* readability-container-size-empty
* readability-delete-null-pointer
* readability-else-after-return
* readability-inconsistent-declaration-parameter-name
* readability-redundant-member-init
* readability-redundant-smartptr-get
* readability-redundant-string-cstr
* readability-use-anyofallof
* readability-static-definition-in-anonymous-namespace
* readability-static-accessed-through-instance
* readability-simplify-boolean-expr
2023-11-16 01:22:08 +01:00
wmayer
9c7d00ffcb fix readability-identifier-length 2023-11-16 01:22:08 +01:00
wmayer
985def3416 Base: apply clang format 2023-11-13 12:01:26 -05:00
Chris Hennes
80be10c643 Base/Toponaming: Refactor to extract filters to new file 2023-10-10 11:28:30 -05:00
Chris Hennes
023ff7f388 App/Toponaming: Linter cleanup of Base64 code
Does not address pointer arithmetic or array indexing complaints.
2023-10-10 10:19:44 -05:00
Chris Hennes
33abb7b5b1 App/Toponaming: Add base64 encoding to XML 2023-10-10 10:19:43 -05:00
wmayer
097d5d6fee Base: C++ core guidelines: init variables 2023-08-24 18:48:52 +02:00
wmayer
4210ab01e0 Base: modernize C++: use default member init 2023-08-23 19:51:44 +02:00
wmayer
dbad96d43e modernize C++: use using 2023-08-06 23:17:10 +02:00
marioalexis
623e65f2f0 Base: Include needed header file 2023-05-16 12:46:34 -03:00
Chris Hennes
ec575c612a App/Toponaming: Add missing include to Writer 2023-05-11 14:34:35 -05:00
Chris Hennes
cc7effcfc7 App/Toponaming: Lint and compilation cleanup 2023-05-11 14:34:35 -05:00
Chris Hennes
9ebaa34e1e App/Toponaming: Add supporting code
Support for reading and writing binary data, and a small tweak to bitmask.
2023-05-11 14:34:35 -05:00
berniev
15419982d4 Base: Modernise ctors dtors defs etc 2022-08-02 12:37:46 +02:00
wmayer
455ed09240 C++ core guidelines:
* ES.87: Don’t add redundant == or != to conditions
2022-06-25 17:38:57 +02:00
wmayer
bec323b793 Base: cosmetic changes 2022-05-12 17:49:55 +02:00
wmayer
a6624ef264 Base: fix warnings from code analysers:
* replace some C-style casts with static_cast
* remove unneeded destructors
* define default copy-constructor and assignment operator
2022-03-05 19:03:21 +01:00
Uwe
5b1114e914 [Base] Reader and Writer: remove unused includes 2022-02-27 23:54:00 +01:00
Uwe
ca8d93bb97 [Base] remove unused code 2022-02-27 19:30:09 +01:00
wmayer
cad0d01883 Base: modernize C++11
* remove redundant void-arg
* use nullptr
* replace deprecated headers
2022-01-25 20:21:30 +01:00
luz paz
01b21e0d06 Base: Fix header uniformity, whitespace, and doxygen
[skip ci]
2020-11-22 18:12:16 +01:00
wmayer
41ca54de70 LGTM: [skip ci] remove some obsolete FIXME comments from source code 2020-07-28 09:49:20 +02:00
luz.paz
011e5aedfa src/Base: [skip ci] fix header uniformity
This PR fixes header uniformity across all `src/Base` files
2019-12-25 11:38:58 +01:00
asapelkin
875a463923 Used single quotes for single character in string::find algorithm, more efficient 2019-11-21 18:59:43 +01:00
wmayer
ce975cef2a avoid using hard-code precision when writing double to streams 2019-02-23 14:58:41 +01:00
Abdullah Tahiri
ff0b5a288f ZipStream: Change precision from 12 to 16 decimals
==================================================

Fixes:
https://forum.freecadweb.org/viewtopic.php?f=3&t=32212&start=10#p269080
2018-11-19 11:31:08 +01:00
wmayer
fb7094bf31 use specialized exception classes 2017-04-28 18:49:11 +02:00
wmayer
eb05da7cd7 + fixes #0001237: the project file is not saved when the /tmp directory is full, but the user is not aware of it 2015-09-19 18:59:22 +02:00
wmayer
718b766737 + for file-based recovery write the data files in worker threads 2015-09-19 13:12:59 +02:00
wmayer
193abe75da + make RecoveryWriter more robust 2015-09-18 15:32:33 +02:00
wmayer
698f964aa3 + implement FileWriter class based on files and a specialized sub-class for recovery purposes 2015-09-17 21:37:47 +02:00
wmayer
22b7fb660c + save Brep in binary format for recovery files 2015-09-16 22:58:47 +02:00
Sebastian Hoogen
b311c93262 use 4 spaces to indent XML output 2014-12-10 01:33:51 +01:00
wmayer
ad49408c58 Support to write vector list and float lists in old format, fix issues in property editor, move back to float for curvature type 2013-03-30 12:32:53 +01:00
wmayer
399d9468f4 Implement CDATA reader, fix bugs in Writer::insertBinFile 2012-05-31 11:50:25 +02:00
wmayer
c812315b51 fix some issues when writing binary data into an XML file 2012-05-10 12:07:37 +02:00
wmayer
a65d4fdda6 + implement global draw styles
+ use double precision in XML file
+ fix crash with in SoBrepFaceSet

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5083 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
2011-11-01 13:52:38 +00:00
wmayer
120ca87015 + unify DLL export defines to namespace names
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
2011-10-10 13:44:52 +00:00