Author: zooey Date: 2011-02-15 19:52:03 +0100 (Tue, 15 Feb 2011) New Revision: 40518 Changeset: http://dev.haiku-os.org/changeset/40518 Added: haiku/trunk/headers/private/package/HashableString.h Modified: haiku/trunk/src/kits/package/RepositoryCache.cpp haiku/trunk/src/kits/package/hpkg/RepositoryWriterImpl.cpp Log: * prefer HashSet and HashMap to respective std-classes where possible Added: haiku/trunk/headers/private/package/HashableString.h =================================================================== --- haiku/trunk/headers/private/package/HashableString.h (rev 0) +++ haiku/trunk/headers/private/package/HashableString.h 2011-02-15 18:52:03 UTC (rev 40518) @@ -0,0 +1,70 @@ +/* + * Copyright 2011, Oliver Tappe <zooey@xxxxxxxxxxxxxxx> + * Distributed under the terms of the MIT License. + */ +#ifndef _PACKAGE__PRIVATE__HASHABLE_STRING_H_ +#define _PACKAGE__PRIVATE__HASHABLE_STRING_H_ + + +#include <String.h> + +#include <HashString.h> + + +namespace BPackageKit { + +namespace BPrivate { + + +class HashableString : public BString { +public: + inline HashableString(); + + inline HashableString(const BString& string); + + inline uint32 GetHashCode() const; + + inline bool operator!= (const HashableString& other) const; + +private: + uint32 fHashCode; +}; + + +inline +HashableString::HashableString() + : + fHashCode(0) +{ +} + + +inline +HashableString::HashableString(const BString& string) + : + BString(string), + fHashCode(string_hash(String())) +{ +} + + +inline uint32 +HashableString::GetHashCode() const +{ + return fHashCode; +} + + +inline bool +HashableString::operator!= (const HashableString& other) const +{ + return Compare(other) != 0 || fHashCode != other.fHashCode; +} + + +} // namespace BPrivate + +} // namespace BPackageKit + + +#endif // _PACKAGE__PRIVATE__HASHABLE_STRING_H_ Modified: haiku/trunk/src/kits/package/RepositoryCache.cpp =================================================================== --- haiku/trunk/src/kits/package/RepositoryCache.cpp 2011-02-15 18:33:19 UTC (rev 40517) +++ haiku/trunk/src/kits/package/RepositoryCache.cpp 2011-02-15 18:52:03 UTC (rev 40518) @@ -19,12 +19,12 @@ #include <Path.h> #include <HashMap.h> -#include <HashString.h> #include <package/hpkg/ErrorOutput.h> #include <package/hpkg/PackageInfoAttributeValue.h> #include <package/hpkg/RepositoryContentHandler.h> #include <package/hpkg/RepositoryReader.h> +#include <package/HashableString.h> #include <package/PackageInfo.h> #include <package/RepositoryInfo.h> @@ -32,40 +32,13 @@ namespace BPackageKit { +using BPrivate::HashableString; using namespace BHPKG; namespace { -struct HashableString : public BString { - uint32 hashCode; - - HashableString() - : - hashCode(0) - { - } - - HashableString(const BString& string_) - : - BString(string_), - hashCode(string_hash(String())) - { - } - - inline uint32 GetHashCode() const - { - return hashCode; - } - - inline bool operator!= (const HashableString& other) const - { - return Compare(other) != 0 || hashCode != other.hashCode; - } -}; - - typedef ::BPrivate::HashMap<HashableString, BPackageInfo> PackageHashMap; struct RepositoryContentHandler : BRepositoryContentHandler { Modified: haiku/trunk/src/kits/package/hpkg/RepositoryWriterImpl.cpp =================================================================== --- haiku/trunk/src/kits/package/hpkg/RepositoryWriterImpl.cpp 2011-02-15 18:33:19 UTC (rev 40517) +++ haiku/trunk/src/kits/package/hpkg/RepositoryWriterImpl.cpp 2011-02-15 18:52:03 UTC (rev 40518) @@ -8,13 +8,13 @@ #include <algorithm> #include <new> -#include <set> #include <ByteOrder.h> #include <Message.h> #include <Path.h> #include <AutoDeleter.h> +#include <HashSet.h> #include <package/hpkg/HPKGDefsPrivate.h> #include <package/hpkg/PackageDataReader.h> @@ -23,6 +23,7 @@ #include <package/hpkg/PackageReader.h> #include <package/BlockBufferCacheNoLock.h> #include <package/ChecksumAccessors.h> +#include <package/HashableString.h> #include <package/RepositoryInfo.h> @@ -34,6 +35,7 @@ using BPackageKit::BPrivate::GeneralFileChecksumAccessor; +using BPackageKit::BPrivate::HashableString; namespace { @@ -254,7 +256,8 @@ } // anonymous namespace -struct RepositoryWriterImpl::PackageNameSet : public std::set<BString> { +struct RepositoryWriterImpl::PackageNameSet + : public ::BPrivate::HashSet<HashableString> { }; @@ -281,6 +284,9 @@ { try { fPackageNames = new PackageNameSet(); + status_t result = fPackageNames->InitCheck(); + if (result != B_OK) + return result; return _Init(fileName); } catch (status_t error) { return error; @@ -417,9 +423,7 @@ } // reject package with a name that we've seen already - PackageNameSet::const_iterator namePos - = fPackageNames->find(fPackageInfo.Name()); - if (namePos != fPackageNames->end()) { + if (fPackageNames->Contains(fPackageInfo.Name())) { fListener->PrintError("package %s has already been added!\n", fPackageInfo.Name().String()); return B_NAME_IN_USE; @@ -449,7 +453,8 @@ return B_BAD_DATA; } - fPackageNames->insert(fPackageInfo.Name()); + if ((result = fPackageNames->Add(fPackageInfo.Name())) != B_OK) + return result; RegisterPackageInfo(PackageAttributes(), fPackageInfo); fPackageCount++;