fix putting strings into a pool

This commit is contained in:
unK
2008-09-17 14:54:23 +02:00
parent 89d4eb9f41
commit 5ec6e998ef
2 changed files with 15 additions and 15 deletions

View File

@@ -179,70 +179,70 @@ void Song::SetFile(const string &str)
{
if (itsSong->file)
str_pool_put(itsSong->file);
itsSong->file = str.empty() ? 0 : str_pool_dup(str.c_str());
itsSong->file = str.empty() ? 0 : str_pool_get(str.c_str());
}
void Song::SetArtist(const string &str)
{
if (itsSong->artist)
str_pool_put(itsSong->artist);
itsSong->artist = str.empty() ? 0 : str_pool_dup(str.c_str());
itsSong->artist = str.empty() ? 0 : str_pool_get(str.c_str());
}
void Song::SetTitle(const string &str)
{
if (itsSong->title)
str_pool_put(itsSong->title);
itsSong->title = str.empty() ? 0 : str_pool_dup(str.c_str());
itsSong->title = str.empty() ? 0 : str_pool_get(str.c_str());
}
void Song::SetAlbum(const string &str)
{
if (itsSong->album)
str_pool_put(itsSong->album);
itsSong->album = str.empty() ? 0 : str_pool_dup(str.c_str());
itsSong->album = str.empty() ? 0 : str_pool_get(str.c_str());
}
void Song::SetTrack(const string &str)
{
if (itsSong->track)
str_pool_put(itsSong->track);
itsSong->track = str.empty() ? 0 : str_pool_dup(IntoStr(StrToInt(str)).c_str());
itsSong->track = str.empty() ? 0 : str_pool_get(IntoStr(StrToInt(str)).c_str());
}
void Song::SetTrack(int track)
{
if (itsSong->track)
str_pool_put(itsSong->track);
itsSong->track = str_pool_dup(IntoStr(track).c_str());
itsSong->track = str_pool_get(IntoStr(track).c_str());
}
void Song::SetYear(const string &str)
{
if (itsSong->date)
str_pool_put(itsSong->date);
itsSong->date = str.empty() ? 0 : str_pool_dup(IntoStr(StrToInt(str)).c_str());
itsSong->date = str.empty() ? 0 : str_pool_get(IntoStr(StrToInt(str)).c_str());
}
void Song::SetYear(int year)
{
if (itsSong->date)
str_pool_put(itsSong->date);
itsSong->date = str_pool_dup(IntoStr(year).c_str());
itsSong->date = str_pool_get(IntoStr(year).c_str());
}
void Song::SetGenre(const string &str)
{
if (itsSong->genre)
str_pool_put(itsSong->genre);
itsSong->genre = str.empty() ? 0 : str_pool_dup(str.c_str());
itsSong->genre = str.empty() ? 0 : str_pool_get(str.c_str());
}
void Song::SetComment(const string &str)
{
if (itsSong->comment)
str_pool_put(itsSong->comment);
itsSong->comment = str.empty() ? 0 : str_pool_dup(str.c_str());
itsSong->comment = str.empty() ? 0 : str_pool_get(str.c_str());
}
void Song::SetPosition(int pos)

View File

@@ -38,7 +38,7 @@ calc_hash(const char *p)
{
unsigned hash = 5381;
//assert(p != NULL);
assert(p != NULL);
while (*p != 0)
hash = (hash << 5) + hash + *p++;
@@ -72,7 +72,7 @@ char *str_pool_get(const char *value)
slot_p = &slots[calc_hash(value) % NUM_SLOTS];
for (slot = *slot_p; slot != NULL; slot = slot->next) {
if (strcmp(value, slot->value) == 0 && slot->ref < 0xff) {
//assert(slot->ref > 0);
assert(slot->ref > 0);
++slot->ref;
return slot->value;
}
@@ -87,7 +87,7 @@ char *str_pool_dup(const char *value)
{
struct slot *slot = value_to_slot(value);
//assert(slot->ref > 0);
assert(slot->ref > 0);
if (slot->ref < 0xff) {
++slot->ref;
@@ -108,7 +108,7 @@ void str_pool_put(const char *value)
struct slot **slot_p, *slot;
slot = value_to_slot(value);
//assert(slot->ref > 0);
assert(slot->ref > 0);
--slot->ref;
if (slot->ref > 0)
@@ -117,7 +117,7 @@ void str_pool_put(const char *value)
for (slot_p = &slots[calc_hash(value) % NUM_SLOTS];
*slot_p != slot;
slot_p = &(*slot_p)->next) {
//assert(*slot_p != NULL);
assert(*slot_p != NULL);
}
*slot_p = slot->next;