diff --git a/doomsday/engine/portable/include/file.h b/doomsday/engine/portable/include/file.h index 4068a9061c..2aca0fa429 100644 --- a/doomsday/engine/portable/include/file.h +++ b/doomsday/engine/portable/include/file.h @@ -80,7 +80,7 @@ class File1 virtual ~File1(); /// @return Name of this file. - virtual String /*const&*/ name() const; + virtual String const& name() const; /** * Compose the absolute VFS path to this file. @@ -263,8 +263,11 @@ class File1 /// Categorization flags. Flags flags; - /// Absolute variable-length path in the vfs. - ddstring_t path_; + /// Absolute path (including name) in the vfs. + String path_; + + /// Name of this file. + String name_; /// Load order depth index. uint order; diff --git a/doomsday/engine/portable/include/pathtree.h b/doomsday/engine/portable/include/pathtree.h index 23b1b30b3a..e7a560f262 100644 --- a/doomsday/engine/portable/include/pathtree.h +++ b/doomsday/engine/portable/include/pathtree.h @@ -147,7 +147,7 @@ namespace de } /// @return Name for this node's path fragment. - String /*const&*/ name() const; + String const& name() const; /// @return Hash for this node's path fragment. ushort hash() const; @@ -306,7 +306,7 @@ namespace de */ /// @return The path fragment associated with @a fragmentId. - String /*const&*/ fragmentName(FragmentId fragmentId) const; + String const& fragmentName(FragmentId fragmentId) const; /// @return Hash associated with @a fragmentId. ushort fragmentHash(FragmentId fragmentId) const; diff --git a/doomsday/engine/portable/src/dd_wad.cpp b/doomsday/engine/portable/src/dd_wad.cpp index 03a5916bb0..c18196d82f 100644 --- a/doomsday/engine/portable/src/dd_wad.cpp +++ b/doomsday/engine/portable/src/dd_wad.cpp @@ -58,7 +58,7 @@ AutoStr* W_LumpName(lumpnum_t absoluteLumpNum) try { lumpnum_t lumpNum = absoluteLumpNum; - String /*const&*/ name = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name(); + String const& name = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name(); QByteArray nameUtf8 = name.toUtf8(); return AutoStr_FromTextStd(nameUtf8.constData()); } diff --git a/doomsday/engine/portable/src/edit_map.cpp b/doomsday/engine/portable/src/edit_map.cpp index 82e4355bc4..02bc6c18f4 100644 --- a/doomsday/engine/portable/src/edit_map.cpp +++ b/doomsday/engine/portable/src/edit_map.cpp @@ -1766,7 +1766,7 @@ static int printMissingMaterialWorker(de::StringPool::Id internId, void* paramet { // Print mode. int const refCount = materialDict->userValue(internId); - de::String /*const&*/ materialUri = materialDict->string(internId); + de::String const& materialUri = materialDict->string(internId); QByteArray materialUriUtf8 = materialUri.toUtf8(); Con_Message(" %4u x \"%s\"\n", refCount, materialUriUtf8.constData()); } diff --git a/doomsday/engine/portable/src/file.cpp b/doomsday/engine/portable/src/file.cpp index 3bb5fe92d7..babd4c2434 100644 --- a/doomsday/engine/portable/src/file.cpp +++ b/doomsday/engine/portable/src/file.cpp @@ -29,21 +29,19 @@ namespace de { File1::File1(FileHandle& hndl, char const* _path, FileInfo const& _info, File1* _container) - : handle_(&hndl), info_(_info), container_(_container), flags(DefaultFlags) + : handle_(&hndl), info_(_info), container_(_container), + flags(DefaultFlags), path_(String(_path)), name_(String(_path).fileName()) { // Used to favor newer files when duplicates are pruned. /// @todo Does not belong at this level. Load order should be determined /// at file system level. -ds static uint fileCounter = 0; order = fileCounter++; - - Str_Init(&path_); Str_Set(&path_, _path); } File1::~File1() { App_FileSystem()->releaseFile(*this); - Str_Free(&path_); if(handle_) delete handle_; } @@ -70,9 +68,8 @@ de::FileHandle& File1::handle() String File1::composePath(char delimiter) const { - String result = String(Str_Text(&path_)); - if(delimiter != '/') - throw de::Error("File1::composePath", "Non '/' delimiter not yet implemented"); + String result = path_; + if(delimiter != '/') throw Error("File1::composePath", "Non '/' delimiter not yet implemented"); return result; } @@ -105,11 +102,9 @@ File1& File1::setCustom(bool yes) return *this; } -String /*const&*/ File1::name() const +String const& File1::name() const { - /// @todo Contained files will be able to provide the name without needing to - /// extract it from the virtual path. - return String(Str_Text(&path_)).fileName(); + return name_; } size_t File1::read(uint8_t* /*buffer*/, bool /*tryCache*/) diff --git a/doomsday/engine/portable/src/fs_main.cpp b/doomsday/engine/portable/src/fs_main.cpp index 71d6629d8a..0494536903 100644 --- a/doomsday/engine/portable/src/fs_main.cpp +++ b/doomsday/engine/portable/src/fs_main.cpp @@ -1511,7 +1511,7 @@ AutoStr* F_LumpName(lumpnum_t absoluteLumpNum) try { lumpnum_t lumpNum = absoluteLumpNum; - String /*const&*/ name = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name(); + String const& name = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).name(); QByteArray nameUtf8 = name.toUtf8(); return AutoStr_FromTextStd(nameUtf8.constData()); } diff --git a/doomsday/engine/portable/src/p_data.cpp b/doomsday/engine/portable/src/p_data.cpp index 9267f5442b..b4bd63c219 100644 --- a/doomsday/engine/portable/src/p_data.cpp +++ b/doomsday/engine/portable/src/p_data.cpp @@ -289,7 +289,7 @@ AutoStr* P_NameForMapEntityDef(MapEntityDef* def) if(def) { de::StringPool::Id id = entityDefs->iterate(P_NameForMapEntityDefWorker, def); - de::String /*const&*/ name = entityDefs->string(id); + de::String const& name = entityDefs->string(id); QByteArray nameUtf8 = name.toUtf8(); return AutoStr_FromText(nameUtf8.constData()); } diff --git a/doomsday/engine/portable/src/pathtree.cpp b/doomsday/engine/portable/src/pathtree.cpp index d98195a726..d57c918642 100644 --- a/doomsday/engine/portable/src/pathtree.cpp +++ b/doomsday/engine/portable/src/pathtree.cpp @@ -288,7 +288,7 @@ PathTree::Node& PathTree::find(int flags, char const* searchPath, char delimiter return *foundNode; } -String /*const&*/ PathTree::fragmentName(FragmentId fragmentId) const +String const& PathTree::fragmentName(FragmentId fragmentId) const { return d->fragments.string(fragmentId); } diff --git a/doomsday/engine/portable/src/pathtreenode.cpp b/doomsday/engine/portable/src/pathtreenode.cpp index bbacfc7073..46add76349 100644 --- a/doomsday/engine/portable/src/pathtreenode.cpp +++ b/doomsday/engine/portable/src/pathtreenode.cpp @@ -86,7 +86,7 @@ PathTree::FragmentId PathTree::Node::fragmentId() const return d->fragmentId; } -String /*const&*/ PathTree::Node::name() const +String const& PathTree::Node::name() const { return tree().fragmentName(d->fragmentId); } @@ -184,7 +184,7 @@ int PathTree::Node::comparePath(PathMap& searchPattern, int flags) const int sfragmentLength = sfragment->length(); qstrncpy(buf, sfragment->from, sfragmentLength + 1); - String /*const&*/ fragment = node->name(); + String const& fragment = node->name(); QByteArray fragmentUtf8 = fragment.toUtf8(); if(!matchPathFragment(fragmentUtf8.constData(), buf)) { @@ -230,7 +230,7 @@ typedef struct pathconstructorparams_s { */ static void pathConstructor(pathconstructorparams_t& parm, PathTree::Node const& trav) { - String /*const&*/ fragment = trav.name(); + String const& fragment = trav.name(); #ifdef LIBDENG_STACK_MONITOR maxStackDepth = MAX_OF(maxStackDepth, stackStart - (void*)&fragment); diff --git a/doomsday/engine/portable/src/resource/models.cpp b/doomsday/engine/portable/src/resource/models.cpp index 13854c0889..04c8a4a50e 100644 --- a/doomsday/engine/portable/src/resource/models.cpp +++ b/doomsday/engine/portable/src/resource/models.cpp @@ -411,7 +411,7 @@ model_t* R_ModelForId(uint modelRepositoryId) AutoStr* R_ComposePathForModelId(uint modelRepositoryId) { DENG_ASSERT(modelRepository); - de::String /*const&*/ path = modelRepository->string(modelRepositoryId); + de::String const& path = modelRepository->string(modelRepositoryId); QByteArray pathUtf8 = path.toUtf8(); return AutoStr_FromTextStd(pathUtf8.constData()); } @@ -510,7 +510,7 @@ static int R_LoadModel(de::Uri const& uri) if(!numFoundSkins) { // Lastly try a skin named similarly to the model in the same directory. - de::String /*const&*/ mdlFileName = modelRepository->string(index); + de::String const& mdlFileName = modelRepository->string(index); de::String skinSearchPath = mdlFileName.fileNamePath() / "/" / mdlFileName.fileNameWithoutExtension(); QByteArray skinSearchPathUtf8 = skinSearchPath.toUtf8(); diff --git a/doomsday/engine/portable/src/resourcenamespace.cpp b/doomsday/engine/portable/src/resourcenamespace.cpp index fd3115cb0f..b01fddc7d2 100644 --- a/doomsday/engine/portable/src/resourcenamespace.cpp +++ b/doomsday/engine/portable/src/resourcenamespace.cpp @@ -416,7 +416,7 @@ bool ResourceNamespace::add(PathTree::Node& resourceNode) // We are only interested in leafs (i.e., files and not folders). if(!resourceNode.isLeaf()) return false; - String /*const&*/ name_ = resourceNode.name(); + String const& name_ = resourceNode.name(); QByteArray name_Utf8 = name_.toUtf8(); AutoStr* name = composeResourceName(name_Utf8.constData()); NameHash::key_type key = hashResourceName(name); diff --git a/doomsday/engine/portable/src/wad.cpp b/doomsday/engine/portable/src/wad.cpp index 0ca6edaadd..3dbcd41568 100644 --- a/doomsday/engine/portable/src/wad.cpp +++ b/doomsday/engine/portable/src/wad.cpp @@ -63,7 +63,7 @@ class WadFile : public File1 {} /// @return Name of this file. - String /*const&*/ name() const + String const& name() const { return directoryNode().name(); } @@ -157,7 +157,7 @@ class WadFile : public File1 crc_ = uint(info_.size); PathTree::Node const& node = directoryNode(); - String /*const&*/ name = node.name(); + String const& name = node.name(); int const nameLen = name.length(); for(int k = 0; k < nameLen; ++k) { diff --git a/doomsday/engine/portable/src/zip.cpp b/doomsday/engine/portable/src/zip.cpp index 8e32375682..c54c55faf1 100644 --- a/doomsday/engine/portable/src/zip.cpp +++ b/doomsday/engine/portable/src/zip.cpp @@ -146,7 +146,7 @@ class ZipFile : public File1 {} /// @return Name of this file. - String /*const&*/ name() const + String const& name() const { return directoryNode().name(); } diff --git a/doomsday/libdeng/include/de/stringpool.h b/doomsday/libdeng/include/de/stringpool.h index 450fa2274c..d107507795 100644 --- a/doomsday/libdeng/include/de/stringpool.h +++ b/doomsday/libdeng/include/de/stringpool.h @@ -121,7 +121,7 @@ namespace de * * @return The interned copy of the string owned by the pool. */ - String /*const&*/ internAndRetrieve(String str); + String const& internAndRetrieve(String str); /** * Sets the user-specified custom value associated with the string @a id. @@ -179,7 +179,7 @@ namespace de * * @return Interned string associated with @a internId. Owned by the pool. */ - String /*const&*/ string(Id id) const; + String const& string(Id id) const; /** * Removes a string from the pool. diff --git a/doomsday/libdeng/src/stringpool.cpp b/doomsday/libdeng/src/stringpool.cpp index d6929ebf57..6e6c7ee29b 100644 --- a/doomsday/libdeng/src/stringpool.cpp +++ b/doomsday/libdeng/src/stringpool.cpp @@ -319,7 +319,7 @@ StringPool::Id StringPool::intern(String str) return EXPORT_ID(d->copyAndAssignUniqueId(str)); // O(log n) } -String /*const&*/ StringPool::internAndRetrieve(String str) +String const& StringPool::internAndRetrieve(String str) { InternalId id = IMPORT_ID(intern(str)); return *d->idMap[id]; @@ -386,9 +386,9 @@ StringPool::Id StringPool::isInterned(String str) const return 0; } -String /*const&*/ StringPool::string(Id id) const +String const& StringPool::string(Id id) const { - if(id == 0) return ""; + if(id == 0) return nullString; /// @todo Should error? InternalId const internalId = IMPORT_ID(id); DENG_ASSERT(internalId < d->idMap.size()); @@ -535,14 +535,14 @@ LIBDENG_DEFINE_UNITTEST(StringPool) // Another string. s = String("abc"); - String /*const&*/ is = p.internAndRetrieve(s); + String const& is = p.internAndRetrieve(s); DENG_ASSERT(!is.compare(s)); String s2 = String("ABC"); - is = p.internAndRetrieve(s2); - DENG_ASSERT(!is.compare(s)); + String const& is2 = p.internAndRetrieve(s2); + DENG_ASSERT(!is2.compare(s)); - DENG_ASSERT(p.intern(is) == 2); + DENG_ASSERT(p.intern(is2) == 2); DENG_ASSERT(p.size() == 2); //p.print(); diff --git a/doomsday/plugins/wadmapconverter/include/id1map.h b/doomsday/plugins/wadmapconverter/include/id1map.h index 8b64e8f13b..96121bbfd7 100644 --- a/doomsday/plugins/wadmapconverter/include/id1map.h +++ b/doomsday/plugins/wadmapconverter/include/id1map.h @@ -83,7 +83,7 @@ class Id1Map MaterialDictId addMaterialToDictionary(const char* name, MaterialDictGroup group); private: - inline de::String /*const&*/ findMaterialInDictionary(MaterialDictId id) + inline de::String const& findMaterialInDictionary(MaterialDictId id) { return materials.string(id); } @@ -92,7 +92,7 @@ class Id1Map AutoStr* composeMaterialRef(MaterialDictId id) { AutoStr* ref = AutoStr_NewStd(); - de::String /*const&*/ material = findMaterialInDictionary(id); + de::String const& material = findMaterialInDictionary(id); QByteArray materialUtf8 = material.toUtf8(); Str_Set(ref, materialUtf8.constData()); return ref;