diff options
-rw-r--r-- | scripts/src/lib.lua | 2 | ||||
-rw-r--r-- | src/lib/util/cstrpool.cpp | 114 | ||||
-rw-r--r-- | src/lib/util/cstrpool.h | 65 |
3 files changed, 0 insertions, 181 deletions
diff --git a/scripts/src/lib.lua b/scripts/src/lib.lua index 7353c87c1d9..1549084c918 100644 --- a/scripts/src/lib.lua +++ b/scripts/src/lib.lua @@ -48,8 +48,6 @@ project "utils" MAME_DIR .. "src/lib/util/corestr.h", MAME_DIR .. "src/lib/util/coreutil.cpp", MAME_DIR .. "src/lib/util/coreutil.h", - MAME_DIR .. "src/lib/util/cstrpool.cpp", - MAME_DIR .. "src/lib/util/cstrpool.h", MAME_DIR .. "src/lib/util/delegate.cpp", MAME_DIR .. "src/lib/util/delegate.h", MAME_DIR .. "src/lib/util/flac.cpp", diff --git a/src/lib/util/cstrpool.cpp b/src/lib/util/cstrpool.cpp deleted file mode 100644 index 5a9e571366b..00000000000 --- a/src/lib/util/cstrpool.cpp +++ /dev/null @@ -1,114 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/*************************************************************************** - - cstrpool.c - - Constant string pool helper class. - -***************************************************************************/ - -#include <assert.h> - -#include "cstrpool.h" - - -//************************************************************************** -// CONST STRING POOL -//************************************************************************** - -//------------------------------------------------- -// const_string_pool - constructor -//------------------------------------------------- - -const_string_pool::const_string_pool() -{ -} - - -//------------------------------------------------- -// add - add a string to the string pool -//------------------------------------------------- - -const char *const_string_pool::add(const char *string) -{ - // if nullptr or a small number (for some hash strings), just return as-is - if (FPTR(string) < 0x100) - return string; - - // scan to find space - for (pool_chunk *chunk = m_chunklist.first(); chunk != nullptr; chunk = chunk->next()) - { - const char *result = chunk->add(string); - if (result != nullptr) - return result; - } - - // no space anywhere, create a new pool and prepend it (so it gets used first) - const char *result = m_chunklist.prepend(*global_alloc(pool_chunk)).add(string); - assert(result != nullptr); - return result; -} - - -//------------------------------------------------- -// contains - determine if the given string -// pointer lives in the pool -//------------------------------------------------- - -bool const_string_pool::contains(const char *string) -{ - // if nullptr or a small number (for some hash strings), then yes, effectively - if (FPTR(string) < 0x100) - return true; - - // scan to find it - for (pool_chunk *chunk = m_chunklist.first(); chunk != nullptr; chunk = chunk->next()) - if (chunk->contains(string)) - return true; - - return false; -} - -/** - * @fn const_string_pool::pool_chunk::pool_chunk() - * - * @brief ------------------------------------------------- - * pool_chunk - constructor - * -------------------------------------------------. - */ - -const_string_pool::pool_chunk::pool_chunk() - : m_next(nullptr), - m_used(0) -{ -} - -/** - * @fn const char *const_string_pool::pool_chunk::add(const char *string) - * - * @brief ------------------------------------------------- - * add - add a string to this pool - * -------------------------------------------------. - * - * @param string The string to add. - * - * @return null if it fails, else a char*. - */ - -const char *const_string_pool::pool_chunk::add(const char *string) -{ - // get the length of the string (no string can be longer than a full pool) - int bytes = strlen(string) + 1; - assert(bytes < POOL_SIZE); - - // if too big, return nullptr - if (m_used + bytes > POOL_SIZE) - return nullptr; - - // allocate, copy, and return the memory - char *dest = &m_buffer[m_used]; - m_used += bytes; - memcpy(dest, string, bytes); - return dest; -} diff --git a/src/lib/util/cstrpool.h b/src/lib/util/cstrpool.h deleted file mode 100644 index ff6b4c4c0ee..00000000000 --- a/src/lib/util/cstrpool.h +++ /dev/null @@ -1,65 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Aaron Giles -/********************************************************************* - - cstrpool.h - - Constant string pool helper class. - -*********************************************************************/ - -#pragma once - -#ifndef __CSTRPOOL_H_ -#define __CSTRPOOL_H_ - -#include "coretmpl.h" - - -//************************************************************************** -// TYPE DEFINITIONS -//************************************************************************** - -// ======================> const_string_pool - -// a pool to hold constant strings efficiently -class const_string_pool -{ -public: - // construction - const_string_pool(); - - // operations - void reset() { m_chunklist.reset(); } - const char *add(const char *string); - bool contains(const char *string); - -private: - // shared string pool - class pool_chunk - { - static const int POOL_SIZE = 4096; - friend class simple_list<pool_chunk>; - - public: - // construction - pool_chunk(); - - // getters - pool_chunk *next() const { return m_next; } - - // operations - const char *add(const char *string); - bool contains(const char *string) const { return (string >= m_buffer && string < &m_buffer[POOL_SIZE]); } - - private: - // internal state - pool_chunk * m_next; - UINT32 m_used; - char m_buffer[POOL_SIZE]; - }; - simple_list<pool_chunk> m_chunklist; -}; - - -#endif |