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
This commit is contained in:
committed by
Yorik van Havre
parent
844d88fb7a
commit
a2c980f7d6
@@ -247,19 +247,56 @@ std::string Writer::addFile(const char* Name, const Base::Persistence* Object)
|
||||
assert(!isForceXML());
|
||||
|
||||
FileEntry temp;
|
||||
temp.FileName = Name ? Name : "";
|
||||
if (FileNameManager.containsName(temp.FileName)) {
|
||||
temp.FileName = FileNameManager.makeUniqueName(temp.FileName);
|
||||
}
|
||||
temp.FileName = getUniqueFileName(Name);
|
||||
temp.Object = Object;
|
||||
|
||||
FileList.push_back(temp);
|
||||
FileNameManager.addExactName(temp.FileName);
|
||||
|
||||
FileNames.push_back(temp.FileName);
|
||||
|
||||
// return the unique file name
|
||||
return temp.FileName;
|
||||
}
|
||||
|
||||
std::string Writer::getUniqueFileName(const char* Name)
|
||||
{
|
||||
// name in use?
|
||||
std::string CleanName = (Name ? Name : "");
|
||||
std::vector<std::string>::const_iterator pos;
|
||||
pos = find(FileNames.begin(), FileNames.end(), CleanName);
|
||||
|
||||
if (pos == FileNames.end()) {
|
||||
// if not, name is OK
|
||||
return CleanName;
|
||||
}
|
||||
|
||||
std::vector<std::string> names;
|
||||
names.reserve(FileNames.size());
|
||||
FileInfo fi(CleanName);
|
||||
CleanName = fi.fileNamePure();
|
||||
std::string ext = fi.extension();
|
||||
for (pos = FileNames.begin(); pos != FileNames.end(); ++pos) {
|
||||
fi.setFile(*pos);
|
||||
std::string FileName = fi.fileNamePure();
|
||||
if (fi.extension() == ext) {
|
||||
names.push_back(FileName);
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream str;
|
||||
str << Base::Tools::getUniqueName(CleanName, names);
|
||||
if (!ext.empty()) {
|
||||
str << "." << ext;
|
||||
}
|
||||
|
||||
return str.str();
|
||||
}
|
||||
|
||||
const std::vector<std::string>& Writer::getFilenames() const
|
||||
{
|
||||
return FileNames;
|
||||
}
|
||||
|
||||
void Writer::incInd()
|
||||
{
|
||||
if (indent < 1020) {
|
||||
|
||||
Reference in New Issue
Block a user