summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f9409e2)
raw | patch | inline | side by side (parent: f9409e2)
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Thu, 29 Dec 2011 20:17:43 +0000 (21:17 +0100) | ||
committer | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Wed, 4 Jan 2012 17:48:06 +0000 (18:48 +0100) |
Makefile.am | patch | blob | history | |
src/str_pool.c | [deleted file] | patch | blob | history |
src/str_pool.h | [deleted file] | patch | blob | history |
diff --git a/Makefile.am b/Makefile.am
index a6ca4f2e140404ff821406e5cf41640d38aea783..404edcbdf837913cf96eb53f89bef0578f1e6ed2 100644 (file)
--- a/Makefile.am
+++ b/Makefile.am
src/screen_text.h \
src/plugin.h \
src/lyrics.h \
- src/str_pool.h \
src/lirc.h \
src/ncmpc_curses.h
src/charset.c \
src/wreadln.c \
src/strfsong.c \
- src/utils.c \
- src/str_pool.c
+ src/utils.c
if NCMPC_MINI
else
diff --git a/src/str_pool.c b/src/str_pool.c
--- a/src/str_pool.c
+++ /dev/null
@@ -1,126 +0,0 @@
-/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
- * Project homepage: http://musicpd.org
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#include "str_pool.h"
-
-#include <assert.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define NUM_SLOTS 4096
-
-struct slot {
- struct slot *next;
- unsigned char ref;
- char value[1];
-} __attribute__((packed));
-
-static struct slot *slots[NUM_SLOTS];
-
-static inline unsigned
-calc_hash(const char *p)
-{
- unsigned hash = 5381;
-
- assert(p != NULL);
-
- while (*p != 0)
- hash = (hash << 5) + hash + *p++;
-
- return hash;
-}
-
-static inline struct slot *
-value_to_slot(char *value)
-{
- return (struct slot*)(value - offsetof(struct slot, value));
-}
-
-static struct slot *slot_alloc(struct slot *next, const char *value)
-{
- size_t length = strlen(value);
- struct slot *slot = malloc(sizeof(*slot) + length);
- if (slot == NULL)
- abort(); /* XXX */
-
- slot->next = next;
- slot->ref = 1;
- memcpy(slot->value, value, length + 1);
- return slot;
-}
-
-char *str_pool_get(const char *value)
-{
- struct slot **slot_p, *slot;
-
- 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);
- ++slot->ref;
- return slot->value;
- }
- }
-
- slot = slot_alloc(*slot_p, value);
- *slot_p = slot;
- return slot->value;
-}
-
-char *str_pool_dup(char *value)
-{
- struct slot *slot = value_to_slot(value);
-
- assert(slot->ref > 0);
-
- if (slot->ref < 0xff) {
- ++slot->ref;
- return value;
- } else {
- /* the reference counter overflows above 0xff;
- duplicate the value, and start with 1 */
- struct slot **slot_p =
- &slots[calc_hash(slot->value) % NUM_SLOTS];
- slot = slot_alloc(*slot_p, slot->value);
- *slot_p = slot;
- return slot->value;
- }
-}
-
-void str_pool_put(char *value)
-{
- struct slot **slot_p, *slot;
-
- slot = value_to_slot(value);
- assert(slot->ref > 0);
- --slot->ref;
-
- if (slot->ref > 0)
- return;
-
- for (slot_p = &slots[calc_hash(value) % NUM_SLOTS];
- *slot_p != slot;
- slot_p = &(*slot_p)->next) {
- assert(*slot_p != NULL);
- }
-
- *slot_p = slot->next;
- free(slot);
-}
diff --git a/src/str_pool.h b/src/str_pool.h
--- a/src/str_pool.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* ncmpc (Ncurses MPD Client)
- * (c) 2004-2010 The Music Player Daemon Project
- * Project homepage: http://musicpd.org
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef STR_POOL_H
-#define STR_POOL_H
-
-char *str_pool_get(const char *value);
-
-char *str_pool_dup(char *value);
-
-void str_pool_put(char *value);
-
-#endif