PackageWriterImpl::_AttributeRemoved(): Update string cache
When removing a string attribute, decrement the referenced string's usage count in the string cache. This fixes the potentially incorrect usage counts in update mode. Not a serious problem, but it could lead to only singly (or no longer) used strings to be written to the string subsection instead of encoding them inline and thus to slightly greater file sizes.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Ingo Weinhold, [email protected].
|
* Copyright 2009-2013, Ingo Weinhold, [email protected].
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
#ifndef _PACKAGE__HPKG__PRIVATE__STRINGS_H_
|
#ifndef _PACKAGE__HPKG__PRIVATE__STRINGS_H_
|
||||||
@@ -89,11 +89,11 @@ struct CachedStringUsageGreater {
|
|||||||
|
|
||||||
|
|
||||||
struct StringCache : public CachedStringTable {
|
struct StringCache : public CachedStringTable {
|
||||||
StringCache();
|
StringCache();
|
||||||
~StringCache();
|
~StringCache();
|
||||||
|
|
||||||
CachedString* Get(const char* value);
|
|
||||||
|
|
||||||
|
CachedString* Get(const char* value);
|
||||||
|
void Put(CachedString* string);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1052,7 +1052,8 @@ PackageWriterImpl::_AttributeRemoved(Attribute* attribute)
|
|||||||
&& value.encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP) {
|
&& value.encoding == B_HPKG_ATTRIBUTE_ENCODING_RAW_HEAP) {
|
||||||
if (!fHeapRangesToRemove->AddRange(value.data.offset, value.data.size))
|
if (!fHeapRangesToRemove->AddRange(value.data.offset, value.data.size))
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
} else if (value.type == B_HPKG_ATTRIBUTE_TYPE_STRING)
|
||||||
|
fStringCache.Put(value.string);
|
||||||
|
|
||||||
for (DoublyLinkedList<Attribute>::Iterator it
|
for (DoublyLinkedList<Attribute>::Iterator it
|
||||||
= attribute->children.GetIterator();
|
= attribute->children.GetIterator();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
|
* Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -70,6 +70,18 @@ StringCache::Get(const char* value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
StringCache::Put(CachedString* string)
|
||||||
|
{
|
||||||
|
if (string != NULL) {
|
||||||
|
if (--string->usageCount == 0) {
|
||||||
|
Remove(string);
|
||||||
|
delete string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|
||||||
} // namespace BHPKG
|
} // namespace BHPKG
|
||||||
|
|||||||
Reference in New Issue
Block a user