Skip to content

Commit 8de0307

Browse files
committed
std unordered map is a hash table and faster it seems with some simple testing
1 parent 31a3872 commit 8de0307

12 files changed

Lines changed: 17 additions & 17 deletions

src/color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <string.h> // do not remove
1313
#include <strings.h> // do not remove, strcasecmp
1414

15-
using colors = std::map< std::string, color >;
15+
using colors = std::unordered_map< std::string, color >;
1616

1717
colors color_map;
1818
static bool color_init_done;

src/command.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ class command_t
9999
command_fn_t callback;
100100
};
101101

102-
typedef std::shared_ptr< class command_t > commandp;
103-
typedef std::map< std::string, commandp > commands;
104-
static commands commands_map;
102+
typedef std::shared_ptr< class command_t > commandp;
103+
typedef std::unordered_map< std::string, commandp > commands;
104+
static commands commands_map;
105105

106106
static uint8_t command_inited;
107107

src/font.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Fontp font_pixelart_large;
1111
Fontp font_ascii;
1212
Fontp font_ui;
1313

14-
static std::map< std::string, Fontp > fonts;
14+
static std::unordered_map< std::string, Fontp > fonts;
1515

1616
void font_fini(void) { TRACE_AND_INDENT(); }
1717

src/music.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class music
2626
uint32_t rate = 44100;
2727
};
2828

29-
static std::map< std::string, class music * > all_music;
29+
static std::unordered_map< std::string, class music * > all_music;
3030

3131
static std::string music_current;
3232

src/my_ramdisk.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using ramdisk_t = struct ramdisk_t_ {
1212
int len;
1313
};
1414

15-
extern std::map< std::string, ramdisk_t_ > ramdisk_data;
15+
extern std::unordered_map< std::string, ramdisk_t_ > ramdisk_data;
1616

1717
extern unsigned char *ramdisk_load(const char *filename, int *outlen);
1818
extern void ramdisk_init(void);

src/my_sound.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class sound
4343
float volume {};
4444
};
4545

46-
extern std::map< std::string, class sound * > all_sound;
46+
extern std::unordered_map< std::string, class sound * > all_sound;
4747

4848
enum {
4949
CHANNEL_MISC,

src/python_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void py_init(char *argv[])
138138

139139
PyObject *py_add_module(const char *mod)
140140
{
141-
static std::map< std::string, PyObject * > py_mods;
141+
static std::unordered_map< std::string, PyObject * > py_mods;
142142

143143
auto name = std::string(mod);
144144
auto pmod = py_mods[ name ];

src/ramdisk_read.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "my_ramdisk.hpp"
1010
#include "my_sys.hpp"
1111

12-
std::map< std::string, ramdisk_t_ > ramdisk_data;
12+
std::unordered_map< std::string, ramdisk_t_ > ramdisk_data;
1313

1414
unsigned char *ramdisk_load(const char *filename, int *outlen)
1515
{

src/sound.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "my_game.hpp"
77
#include "my_sound.hpp"
88

9-
std::map< std::string, class sound * > all_sound;
9+
std::unordered_map< std::string, class sound * > all_sound;
1010

1111
bool sound_init_done;
1212

src/tex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class Tex
4747
SDL_Surface *surface = {};
4848
};
4949

50-
static std::map< std::string, Texp > textures;
51-
static std::map< std::string, Texp > textures_monochrome;
52-
static std::map< std::string, Texp > textures_mask;
50+
static std::unordered_map< std::string, Texp > textures;
51+
static std::unordered_map< std::string, Texp > textures_monochrome;
52+
static std::unordered_map< std::string, Texp > textures_mask;
5353

5454
uint8_t tex_init(void)
5555
{

0 commit comments

Comments
 (0)