forked from Imagelibrary/binutils-gdb
Use gdb unordered map in tui-io.c
This changes tui.c to use gdb::unordered_map. ui_file_style::color is changed a little as well; operator< is no longer needed, but a simple hash function is added. Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
@@ -42,7 +42,7 @@
|
|||||||
#include "gdbsupport/filestuff.h"
|
#include "gdbsupport/filestuff.h"
|
||||||
#include "completer.h"
|
#include "completer.h"
|
||||||
#include "gdb_curses.h"
|
#include "gdb_curses.h"
|
||||||
#include <map>
|
#include "gdbsupport/unordered_map.h"
|
||||||
#include "pager.h"
|
#include "pager.h"
|
||||||
#include "gdbsupport/gdb-checked-static-cast.h"
|
#include "gdbsupport/gdb-checked-static-cast.h"
|
||||||
|
|
||||||
@@ -178,9 +178,19 @@ tui_putc (char c)
|
|||||||
update_cmdwin_start_line ();
|
update_cmdwin_start_line ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hasher for colors. */
|
||||||
|
|
||||||
|
struct color_hash
|
||||||
|
{
|
||||||
|
size_t operator() (const ui_file_style::color &color) const noexcept
|
||||||
|
{
|
||||||
|
return color.hash ();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/* This maps colors to their corresponding color index. */
|
/* This maps colors to their corresponding color index. */
|
||||||
|
|
||||||
static std::map<ui_file_style::color, int> color_map;
|
static gdb::unordered_map<ui_file_style::color, int, color_hash> color_map;
|
||||||
|
|
||||||
/* This holds a pair of colors and is used to track the mapping
|
/* This holds a pair of colors and is used to track the mapping
|
||||||
between a color pair index and the actual colors. */
|
between a color pair index and the actual colors. */
|
||||||
@@ -190,16 +200,27 @@ struct color_pair
|
|||||||
int fg;
|
int fg;
|
||||||
int bg;
|
int bg;
|
||||||
|
|
||||||
bool operator< (const color_pair &o) const
|
bool operator== (const color_pair &other) const noexcept
|
||||||
{
|
{
|
||||||
return fg < o.fg || (fg == o.fg && bg < o.bg);
|
return fg == other.fg && bg == other.bg;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct color_pair_hash
|
||||||
|
{
|
||||||
|
using is_avalanching = void;
|
||||||
|
|
||||||
|
size_t operator() (const color_pair &val) const noexcept
|
||||||
|
{
|
||||||
|
static_assert (std::has_unique_object_representations_v<color_pair>);
|
||||||
|
return ankerl::unordered_dense::detail::wyhash::hash (&val, sizeof (val));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This maps pairs of colors to their corresponding color pair
|
/* This maps pairs of colors to their corresponding color pair
|
||||||
index. */
|
index. */
|
||||||
|
|
||||||
static std::map<color_pair, int> color_pair_map;
|
static gdb::unordered_map<color_pair, int, color_pair_hash> color_pair_map;
|
||||||
|
|
||||||
/* This is indexed by ANSI color offset from the base color, and holds
|
/* This is indexed by ANSI color offset from the base color, and holds
|
||||||
the corresponding curses color constant. */
|
the corresponding curses color constant. */
|
||||||
|
|||||||
@@ -151,22 +151,12 @@ struct ui_file_style
|
|||||||
return ! (*this == other);
|
return ! (*this == other);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator< (const color &other) const
|
/* Compute a simple hash code for this object. */
|
||||||
|
size_t hash () const
|
||||||
{
|
{
|
||||||
if (m_color_space != other.m_color_space)
|
|
||||||
return m_color_space < other.m_color_space;
|
|
||||||
if (is_simple ())
|
if (is_simple ())
|
||||||
return m_value < other.m_value;
|
return m_value;
|
||||||
if (m_red < other.m_red)
|
return (m_red << 16) + (m_green << 8) + m_red;
|
||||||
return true;
|
|
||||||
if (m_red == other.m_red)
|
|
||||||
{
|
|
||||||
if (m_green < other.m_green)
|
|
||||||
return true;
|
|
||||||
if (m_green == other.m_green)
|
|
||||||
return m_blue < other.m_blue;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
color_space colorspace () const
|
color_space colorspace () const
|
||||||
|
|||||||
Reference in New Issue
Block a user