diff --git a/src/base_media_base.h b/src/base_media_base.h --- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -11,7 +11,6 @@ #define BASE_MEDIA_BASE_H #include "fileio_func.h" -#include "core/smallmap_type.hpp" #include "gfx_type.h" #include "textfile_type.h" #include "textfile_gui.h" diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -22,7 +22,6 @@ add_files( pool_type.hpp random_func.cpp random_func.hpp - smallmap_type.hpp smallstack_type.hpp smallvec_type.hpp span_type.hpp diff --git a/src/core/smallmap_type.hpp b/src/core/smallmap_type.hpp deleted file mode 100644 --- a/src/core/smallmap_type.hpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * This file is part of OpenTTD. - * OpenTTD 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, version 2. - * OpenTTD 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 OpenTTD. If not, see . - */ - -/** @file smallmap_type.hpp Simple mapping class targeted for small sets of data. Stored data shall be POD ("Plain Old Data")! */ - -#ifndef SMALLMAP_TYPE_HPP -#define SMALLMAP_TYPE_HPP - -#include "smallvec_type.hpp" -#include - -/** - * Implementation of simple mapping class. - * It has inherited accessors from std::vector(). - * @tparam T Key type. - * @tparam U Value type. - * @tparam S Unit of allocation. - * - * @see std::vector - */ -template -struct SmallMap : std::vector > { - typedef std::pair Pair; - typedef Pair *iterator; - typedef const Pair *const_iterator; - - /** Creates new SmallMap. Data are initialized in std::vector constructor */ - inline SmallMap() { } - /** Data are freed in std::vector destructor */ - inline ~SmallMap() { } - - /** - * Finds given key in this map - * @param key key to find - * @return &Pair(key, data) if found, this->End() if not - */ - inline typename std::vector::const_iterator Find(const T &key) const - { - return std::find_if(std::vector::begin(), std::vector::end(), [&key](const Pair &pair) { return key == pair.first; }); - } - - /** - * Finds given key in this map - * @param key key to find - * @return &Pair(key, data) if found, this->End() if not - */ - inline Pair *Find(const T &key) - { - for (uint i = 0; i < std::vector::size(); i++) { - if (key == std::vector::operator[](i).first) return &std::vector::operator[](i); - } - return this->End(); - } - - inline const Pair *End() const - { - return std::vector::data() + std::vector::size(); - } - - inline Pair *End() - { - return std::vector::data() + std::vector::size(); - } - - - /** - * Tests whether a key is assigned in this map. - * @param key key to test - * @return true iff the item is present - */ - inline bool Contains(const T &key) const - { - return this->Find(key) != std::vector::end(); - } - - /** - * Tests whether a key is assigned in this map. - * @param key key to test - * @return true iff the item is present - */ - inline bool Contains(const T &key) - { - return this->Find(key) != this->End(); - } - - /** - * Removes given pair from this map - * @param pair pair to remove - * @note it has to be pointer to pair in this map. It is overwritten by the last item. - */ - inline void Erase(Pair *pair) - { - assert(pair >= std::vector::data() && pair < this->End()); - auto distance = pair - std::vector::data(); - std::vector::erase(std::vector::begin() + distance); - } - - /** - * Removes given key from this map - * @param key key to remove - * @return true iff the key was found - * @note last item is moved to its place, so don't increase your iterator if true is returned! - */ - inline bool Erase(const T &key) - { - auto *pair = this->Find(key); - if (pair == this->End()) return false; - - this->Erase(pair); - return true; - } - - /** - * Adds new item to this map. - * @param key key - * @param data data - * @return true iff the key wasn't already present - */ - inline bool Insert(const T &key, const U &data) - { - if (this->Contains(key)) return false; - std::vector::emplace_back(key, data); - return true; - } - - /** - * Returns data belonging to this key - * @param key key - * @return data belonging to this key - * @note if this key wasn't present, new entry is created - */ - inline U &operator[](const T &key) - { - for (uint i = 0; i < std::vector::size(); i++) { - if (key == std::vector::operator[](i).first) return std::vector::operator[](i).second; - } - Pair &n = std::vector::emplace_back(); - n.first = key; - return n.second; - } -}; - -#endif /* SMALLMAP_TYPE_HPP */ diff --git a/src/fios.h b/src/fios.h --- a/src/fios.h +++ b/src/fios.h @@ -25,7 +25,7 @@ enum SaveLoadInvalidateWindowData { SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox) }; -typedef SmallMap CompanyPropertiesMap; +using CompanyPropertiesMap = std::map; /** * Container for loading in mode SL_LOAD_CHECK. diff --git a/src/fontcache/truetypefontcache.cpp b/src/fontcache/truetypefontcache.cpp --- a/src/fontcache/truetypefontcache.cpp +++ b/src/fontcache/truetypefontcache.cpp @@ -167,14 +167,14 @@ const Sprite *TrueTypeFontCache::GetGlyp const void *TrueTypeFontCache::GetFontTable(uint32 tag, size_t &length) { - const FontTable::iterator iter = this->font_tables.Find(tag); - if (iter != this->font_tables.data() + this->font_tables.size()) { + const auto iter = this->font_tables.find(tag); + if (iter != this->font_tables.end()) { length = iter->second.first; return iter->second.second; } const void *result = this->InternalGetFontTable(tag, length); - this->font_tables.Insert(tag, std::pair(length, result)); + this->font_tables[tag] = std::pair(length, result); return result; } diff --git a/src/fontcache/truetypefontcache.h b/src/fontcache/truetypefontcache.h --- a/src/fontcache/truetypefontcache.h +++ b/src/fontcache/truetypefontcache.h @@ -10,7 +10,6 @@ #ifndef TRUETYPEFONTCACHE_H #define TRUETYPEFONTCACHE_H -#include "../core/smallmap_type.hpp" #include "../fontcache.h" @@ -28,7 +27,7 @@ protected: int req_size; ///< Requested font size. int used_size; ///< Used font size. - typedef SmallMap > FontTable; ///< Table with font table cache + using FontTable = std::map>; ///< Table with font table cache FontTable font_tables; ///< Cached font tables. /** Container for information about a glyph. */ diff --git a/src/gamelog.cpp b/src/gamelog.cpp --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -233,25 +233,25 @@ void Gamelog::Print(std::functiongrfid, FGCM_EXACT, this->md5sum); fmt::format_to(output_iterator, "Added NewGRF: "); AddGrfInfo(output_iterator, this->grfid, this->md5sum, gc); - GrfIDMapping::Pair *gm = grf_names.Find(this->grfid); - if (gm != grf_names.End() && !gm->second.was_missing) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was already added!"); + auto gm = grf_names.find(this->grfid); + if (gm != grf_names.end() && !gm->second.was_missing) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was already added!"); grf_names[this->grfid] = gc; } /* virtual */ void LoggedChangeGRFRemoved::FormatTo(std::back_insert_iterator &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) { /* A NewGRF got removed from the game, either manually or by it missing when loading the game. */ - GrfIDMapping::Pair *gm = grf_names.Find(this->grfid); + auto gm = grf_names.find(this->grfid); fmt::format_to(output_iterator, action_type == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: "); - AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr); - if (gm == grf_names.End()) { + AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); + if (gm == grf_names.end()) { fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); } else { if (action_type == GLAT_LOAD) { /* Missing grfs on load are not removed from the configuration */ gm->second.was_missing = true; } else { - grf_names.Erase(gm); + grf_names.erase(gm); } } } @@ -262,38 +262,38 @@ void Gamelog::Print(std::functiongrfid, FGCM_EXACT, this->md5sum); fmt::format_to(output_iterator, "Compatible NewGRF loaded: "); AddGrfInfo(output_iterator, this->grfid, this->md5sum, gc); - if (!grf_names.Contains(this->grfid)) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); + if (grf_names.count(this->grfid) == 0) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); grf_names[this->grfid] = gc; } /* virtual */ void LoggedChangeGRFParameterChanged::FormatTo(std::back_insert_iterator &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) { /* A parameter of a NewGRF got changed after the game was started. */ - GrfIDMapping::Pair *gm = grf_names.Find(this->grfid); + auto gm = grf_names.find(this->grfid); fmt::format_to(output_iterator, "GRF parameter changed: "); - AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr); - if (gm == grf_names.End()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); + AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); + if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); } /* virtual */ void LoggedChangeGRFMoved::FormatTo(std::back_insert_iterator &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) { /* The order of NewGRFs got changed, which might cause some other NewGRFs to behave differently. */ - GrfIDMapping::Pair *gm = grf_names.Find(this->grfid); + auto gm = grf_names.find(this->grfid); fmt::format_to(output_iterator, "GRF order changed: {:08X} moved {} places {}", BSWAP32(this->grfid), abs(this->offset), this->offset >= 0 ? "down" : "up" ); - AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr); - if (gm == grf_names.End()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); + AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); + if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); } /* virtual */ void LoggedChangeGRFBug::FormatTo(std::back_insert_iterator &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) { /* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */ - GrfIDMapping::Pair *gm = grf_names.Find(this->grfid); + auto gm = grf_names.find(this->grfid); assert(this->bug == GBUG_VEH_LENGTH); fmt::format_to(output_iterator, "Rail vehicle changes length outside a depot: GRF ID {:08X}, internal ID 0x{:X}", BSWAP32(this->grfid), this->data); - AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr); - if (gm == grf_names.End()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); + AddGrfInfo(output_iterator, this->grfid, nullptr, gm != grf_names.end() ? gm->second.gc : nullptr); + if (gm == grf_names.end()) fmt::format_to(output_iterator, ". Gamelog inconsistency: GrfID was never added!"); } /* virtual */ void LoggedChangeEmergencySave::FormatTo(std::back_insert_iterator &output_iterator, GrfIDMapping &grf_names, GamelogActionType action_type) diff --git a/src/gamelog_internal.h b/src/gamelog_internal.h --- a/src/gamelog_internal.h +++ b/src/gamelog_internal.h @@ -19,14 +19,14 @@ * So if the gamelog tells a Grf is missing we do not know whether it was readded or completely removed * at some later point. */ -struct GRFPresence{ +struct GRFPresence { const GRFConfig *gc; ///< GRFConfig, if known bool was_missing; ///< Grf was missing during some gameload in the past GRFPresence(const GRFConfig *gc) : gc(gc), was_missing(false) {} GRFPresence() = default; }; -typedef SmallMap GrfIDMapping; +using GrfIDMapping = std::map; struct LoggedChange { LoggedChange(GamelogChangeType type = GLCT_NONE) : ct(type) {} diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -103,8 +103,8 @@ static inline void GetLayouter(Layouter: continue; } - if (!fontMapping.Contains(buff - buff_begin)) { - fontMapping.Insert(buff - buff_begin, f); + if (fontMapping.count(buff - buff_begin) == 0) { + fontMapping[buff - buff_begin] = f; } f = Layouter::GetFont(state.fontsize, state.cur_colour); } @@ -112,8 +112,8 @@ static inline void GetLayouter(Layouter: /* Better safe than sorry. */ *buff = '\0'; - if (!fontMapping.Contains(buff - buff_begin)) { - fontMapping.Insert(buff - buff_begin, f); + if (fontMapping.count(buff - buff_begin) == 0) { + fontMapping[buff - buff_begin] = f; } line.layout = T::GetParagraphLayout(buff_begin, buff, fontMapping); line.state_after = state; @@ -296,12 +296,11 @@ ptrdiff_t Layouter::GetCharAtPosition(in */ Font *Layouter::GetFont(FontSize size, TextColour colour) { - FontColourMap::iterator it = fonts[size].Find(colour); - if (it != fonts[size].End()) return it->second; + FontColourMap::iterator it = fonts[size].find(colour); + if (it != fonts[size].end()) return it->second; - Font *f = new Font(size, colour); - fonts[size].emplace_back(colour, f); - return f; + fonts[size][colour] = new Font(size, colour); + return fonts[size][colour]; } /** diff --git a/src/gfx_layout.h b/src/gfx_layout.h --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -12,7 +12,7 @@ #include "fontcache.h" #include "gfx_func.h" -#include "core/smallmap_type.hpp" +#include "core/math_func.hpp" #include #include @@ -81,7 +81,7 @@ public: }; /** Mapping from index to font. */ -typedef SmallMap FontMap; +using FontMap = std::map; /** * Interface to glue fallback and normal layouter into one. @@ -169,7 +169,7 @@ private: static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state); - typedef SmallMap FontColourMap; + using FontColourMap = std::map; static FontColourMap fonts[FS_END]; public: static Font *GetFont(FontSize size, TextColour colour); diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -266,7 +266,7 @@ const ParagraphLayouter::VisualRun &Fall */ FallbackParagraphLayout::FallbackParagraphLayout(WChar *buffer, int length, FontMap &runs) : buffer_begin(buffer), buffer(buffer), runs(runs) { - assert(runs.End()[-1].first == length); + assert(runs.rbegin()->first == length); } /** @@ -295,15 +295,15 @@ std::unique_ptrbuffer == '\0') { /* Only a newline. */ this->buffer = nullptr; - l->emplace_back(this->runs.front().second, this->buffer, 0, 0); + l->emplace_back(this->runs.begin()->second, this->buffer, 0, 0); return l; } int offset = this->buffer - this->buffer_begin; - FontMap::iterator iter = this->runs.data(); + FontMap::iterator iter = this->runs.begin(); while (iter->first <= offset) { - iter++; - assert(iter != this->runs.End()); + ++iter; + assert(iter != this->runs.end()); } const FontCache *fc = iter->second->fc; @@ -325,8 +325,8 @@ std::unique_ptrbuffer == next_run) { int w = l->GetWidth(); l->emplace_back(iter->second, begin, this->buffer - begin, w); - iter++; - assert(iter != this->runs.End()); + ++iter; + assert(iter != this->runs.end()); next_run = this->buffer_begin + iter->first; begin = this->buffer; diff --git a/src/linkgraph/linkgraph.h b/src/linkgraph/linkgraph.h --- a/src/linkgraph/linkgraph.h +++ b/src/linkgraph/linkgraph.h @@ -11,7 +11,6 @@ #define LINKGRAPH_H #include "../core/pool_type.hpp" -#include "../core/smallmap_type.hpp" #include "../station_base.h" #include "../cargotype.h" #include "../date_type.h" diff --git a/src/network/core/address.h b/src/network/core/address.h --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -14,12 +14,11 @@ #include "config.h" #include "../../company_type.h" #include "../../string_func.h" -#include "../../core/smallmap_type.hpp" class NetworkAddress; typedef std::vector NetworkAddressList; ///< Type for a list of addresses. -typedef SmallMap SocketList; ///< Type for a mapping between address and socket. +using SocketList = std::map; ///< Type for a mapping between address and socket. /** * Wrapper for (un)resolved network addresses; there's no reason to transform diff --git a/src/newgrf.cpp b/src/newgrf.cpp --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -8372,13 +8372,13 @@ static bool ChangeGRFParamValueNames(Byt byte langid = buf->ReadByte(); const char *name_string = buf->ReadString(); - std::pair *val_name = _cur_parameter->value_names.Find(id); - if (val_name != _cur_parameter->value_names.End()) { + auto val_name = _cur_parameter->value_names.find(id); + if (val_name != _cur_parameter->value_names.end()) { AddGRFTextToList(val_name->second, langid, _cur.grfconfig->ident.grfid, false, name_string); } else { GRFTextList list; AddGRFTextToList(list, langid, _cur.grfconfig->ident.grfid, false, name_string); - _cur_parameter->value_names.Insert(id, list); + _cur_parameter->value_names[id] = list; } type = buf->ReadByte(); diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp --- a/src/newgrf_config.cpp +++ b/src/newgrf_config.cpp @@ -264,7 +264,7 @@ void GRFParameterInfo::Finalize() { this->complete_labels = true; for (uint32 value = this->min_value; value <= this->max_value; value++) { - if (!this->value_names.Contains(value)) { + if (this->value_names.count(value) == 0) { this->complete_labels = false; break; } diff --git a/src/newgrf_config.h b/src/newgrf_config.h --- a/src/newgrf_config.h +++ b/src/newgrf_config.h @@ -12,7 +12,6 @@ #include "strings_type.h" #include "core/alloc_type.hpp" -#include "core/smallmap_type.hpp" #include "misc/countedptr.hpp" #include "fileio_type.h" #include "textfile_type.h" @@ -143,7 +142,7 @@ struct GRFParameterInfo { byte param_nr; ///< GRF parameter to store content in byte first_bit; ///< First bit to use in the GRF parameter byte num_bit; ///< Number of bits to use for this parameter - SmallMap value_names; ///< Names for each value. + std::map value_names; ///< Names for each value. bool complete_labels; ///< True if all values have a label. uint32 GetValue(struct GRFConfig *config) const; diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -818,7 +818,7 @@ struct SpriteAlignerWindow : Window { SpriteID current_sprite; ///< The currently shown sprite. Scrollbar *vscroll; - SmallMap offs_start_map; ///< Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window. + std::map offs_start_map; ///< Mapping of starting offsets for the sprites which have been aligned in the sprite aligner window. static bool centre; static bool crosshair; @@ -854,7 +854,7 @@ struct SpriteAlignerWindow : Window { /* Relative offset is new absolute offset - starting absolute offset. * Show 0, 0 as the relative offsets if entry is not in the map (meaning they have not been changed yet). */ - const auto key_offs_pair = this->offs_start_map.Find(this->current_sprite); + const auto key_offs_pair = this->offs_start_map.find(this->current_sprite); if (key_offs_pair != this->offs_start_map.end()) { SetDParam(0, spr->x_offs - key_offs_pair->second.first); SetDParam(1, spr->y_offs - key_offs_pair->second.second); @@ -992,8 +992,8 @@ struct SpriteAlignerWindow : Window { Sprite *spr = const_cast(GetSprite(this->current_sprite, SpriteType::Normal)); /* Remember the original offsets of the current sprite, if not already in mapping. */ - if (!(this->offs_start_map.Contains(this->current_sprite))) { - this->offs_start_map.Insert(this->current_sprite, XyOffs(spr->x_offs, spr->y_offs)); + if (this->offs_start_map.count(this->current_sprite) == 0) { + this->offs_start_map[this->current_sprite] = XyOffs(spr->x_offs, spr->y_offs); } switch (widget) { /* Move eight units at a time if ctrl is pressed. */ @@ -1010,7 +1010,7 @@ struct SpriteAlignerWindow : Window { case WID_SA_RESET_REL: /* Reset the starting offsets for the current sprite. */ - this->offs_start_map.Erase(this->current_sprite); + this->offs_start_map.erase(this->current_sprite); this->SetDirty(); break; diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -283,8 +283,9 @@ struct NewGRFParametersWindow : public W } SetDParam(2, STR_JUST_INT); SetDParam(3, current_value); - if (par_info->value_names.Contains(current_value)) { - const char *label = GetGRFStringFromGRFText(par_info->value_names.Find(current_value)->second); + auto it = par_info->value_names.find(current_value); + if (it != par_info->value_names.end()) { + const char *label = GetGRFStringFromGRFText(it->second); if (label != nullptr) { SetDParam(2, STR_JUST_RAW_STRING); SetDParamStr(3, label); @@ -380,7 +381,7 @@ struct NewGRFParametersWindow : public W DropDownList list; for (uint32 i = par_info->min_value; i <= par_info->max_value; i++) { - list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.Find(i)->second), i, false)); + list.emplace_back(new DropDownListCharStringItem(GetGRFStringFromGRFText(par_info->value_names.find(i)->second), i, false)); } ShowDropDownListAt(this, std::move(list), old_val, -1, wi_rect, COLOUR_ORANGE); diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -26,7 +26,6 @@ #include "date_type.h" #include "debug.h" #include "core/alloc_type.hpp" -#include "core/smallmap_type.hpp" #include "language.h" #include diff --git a/src/os/macosx/font_osx.cpp b/src/os/macosx/font_osx.cpp --- a/src/os/macosx/font_osx.cpp +++ b/src/os/macosx/font_osx.cpp @@ -10,6 +10,7 @@ #include "../../stdafx.h" #include "../../debug.h" #include "font_osx.h" +#include "../../core/math_func.hpp" #include "../../blitter/factory.hpp" #include "../../error_func.h" #include "../../fileio_func.h" diff --git a/src/os/macosx/string_osx.cpp b/src/os/macosx/string_osx.cpp --- a/src/os/macosx/string_osx.cpp +++ b/src/os/macosx/string_osx.cpp @@ -102,8 +102,7 @@ public: /* Extract font information for this run. */ CFRange chars = CTRunGetStringRange(run); - auto map = fontMapping.begin(); - while (map < fontMapping.end() - 1 && map->first <= chars.location) map++; + auto map = fontMapping.upper_bound(chars.location); this->emplace_back(run, map->second, buff); } diff --git a/src/os/windows/font_win32.cpp b/src/os/windows/font_win32.cpp --- a/src/os/windows/font_win32.cpp +++ b/src/os/windows/font_win32.cpp @@ -12,6 +12,7 @@ #include "../../blitter/factory.hpp" #include "../../core/alloc_func.hpp" #include "../../core/math_func.hpp" +#include "../../core/mem_func.hpp" #include "../../error_func.h" #include "../../fileio_func.h" #include "../../fontdetection.h" diff --git a/src/osk_gui.cpp b/src/osk_gui.cpp --- a/src/osk_gui.cpp +++ b/src/osk_gui.cpp @@ -50,8 +50,8 @@ struct OskWindow : public Window { NWidgetCore *par_wid = parent->GetWidget(button); assert(par_wid != nullptr); - assert(parent->querystrings.Contains(button)); - this->qs = parent->querystrings.Find(button)->second; + assert(parent->querystrings.count(button) != 0); + this->qs = parent->querystrings.find(button)->second; this->caption = (par_wid->widget_data != STR_NULL) ? par_wid->widget_data : this->qs->caption; this->text_btn = button; this->text = &this->qs->text; diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -548,7 +548,11 @@ struct PLYRChunkHandler : ChunkHandler { cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE; } - if (!_load_check_data.companies.Insert(index, cprops)) delete cprops; + if (_load_check_data.companies.count(index) == 0) { + _load_check_data.companies[index] = cprops; + } else { + delete cprops; + } } } diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp --- a/src/script/script_config.hpp +++ b/src/script/script_config.hpp @@ -10,7 +10,6 @@ #ifndef SCRIPT_CONFIG_HPP #define SCRIPT_CONFIG_HPP -#include "../core/smallmap_type.hpp" #include "../company_type.h" #include "../textfile_gui.h" #include "script_instance.hpp" diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -3645,7 +3645,7 @@ Town *ClosestTownFromTile(TileIndex tile } static bool _town_rating_test = false; ///< If \c true, town rating is in test-mode. -static SmallMap _town_test_ratings; ///< Map of towns to modified ratings, while in town rating test-mode. +static std::map _town_test_ratings; ///< Map of towns to modified ratings, while in town rating test-mode. /** * Switch the town rating to test-mode, to allow commands to be tested without affecting current ratings. @@ -3675,8 +3675,8 @@ void SetTownRatingTestMode(bool mode) static int GetRating(const Town *t) { if (_town_rating_test) { - SmallMap::iterator it = _town_test_ratings.Find(t); - if (it != _town_test_ratings.End()) { + auto it = _town_test_ratings.find(t); + if (it != _town_test_ratings.end()) { return it->second; } } diff --git a/src/vehicle.cpp b/src/vehicle.cpp --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -678,13 +678,12 @@ void ResetVehicleColourMap() * List of vehicles that should check for autoreplace this tick. * Mapping of vehicle -> leave depot immediately after autoreplace. */ -typedef SmallMap AutoreplaceMap; +using AutoreplaceMap = std::map; static AutoreplaceMap _vehicles_to_autoreplace; void InitializeVehicles() { _vehicles_to_autoreplace.clear(); - _vehicles_to_autoreplace.shrink_to_fit(); ResetVehicleHash(); } @@ -2357,13 +2356,13 @@ void Vehicle::HandleLoading(bool mode) * Get a map of cargoes and free capacities in the consist. * @param capacities Map to be filled with cargoes and capacities. */ -void Vehicle::GetConsistFreeCapacities(SmallMap &capacities) const +void Vehicle::GetConsistFreeCapacities(std::map &capacities) const { for (const Vehicle *v = this; v != nullptr; v = v->Next()) { if (v->cargo_cap == 0) continue; - std::pair *pair = capacities.Find(v->cargo_type); - if (pair == capacities.End()) { - capacities.push_back({v->cargo_type, v->cargo_cap - v->cargo.StoredCount()}); + auto pair = capacities.find(v->cargo_type); + if (pair == capacities.end()) { + capacities[v->cargo_type] = v->cargo_cap - v->cargo.StoredCount(); } else { pair->second += v->cargo_cap - v->cargo.StoredCount(); } diff --git a/src/vehicle_base.h b/src/vehicle_base.h --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -10,7 +10,6 @@ #ifndef VEHICLE_BASE_H #define VEHICLE_BASE_H -#include "core/smallmap_type.hpp" #include "track_type.h" #include "command_type.h" #include "order_base.h" @@ -391,7 +390,7 @@ public: void HandleLoading(bool mode = false); - void GetConsistFreeCapacities(SmallMap &capacities) const; + void GetConsistFreeCapacities(std::map &capacities) const; uint GetConsistTotalCapacity() const; diff --git a/src/window.cpp b/src/window.cpp --- a/src/window.cpp +++ b/src/window.cpp @@ -340,7 +340,7 @@ Scrollbar *Window::GetScrollbar(uint wid */ const QueryString *Window::GetQueryString(uint widnum) const { - auto query = this->querystrings.Find(widnum); + auto query = this->querystrings.find(widnum); return query != this->querystrings.end() ? query->second : nullptr; } @@ -351,8 +351,8 @@ const QueryString *Window::GetQueryStrin */ QueryString *Window::GetQueryString(uint widnum) { - SmallMap::Pair *query = this->querystrings.Find(widnum); - return query != this->querystrings.End() ? query->second : nullptr; + auto query = this->querystrings.find(widnum); + return query != this->querystrings.end() ? query->second : nullptr; } /** @@ -360,8 +360,7 @@ QueryString *Window::GetQueryString(uint */ void Window::UpdateQueryStringSize() { - for (auto &qs : this->querystrings) - { + for (auto &qs : this->querystrings) { qs.second->text.UpdateSize(); } } @@ -1912,7 +1911,7 @@ static void DecreaseWindowCounters() } /* Handle editboxes */ - for (SmallMap::Pair &pair : w->querystrings) { + for (auto &pair : w->querystrings) { pair.second->HandleEditBox(w, pair.first); } diff --git a/src/window_gui.h b/src/window_gui.h --- a/src/window_gui.h +++ b/src/window_gui.h @@ -17,7 +17,6 @@ #include "tile_type.h" #include "widget_type.h" #include "core/smallvec_type.hpp" -#include "core/smallmap_type.hpp" #include "string_type.h" /** @@ -250,7 +249,7 @@ public: ViewportData *viewport; ///< Pointer to viewport data, if present. const NWidgetCore *nested_focus; ///< Currently focused nested widget, or \c nullptr if no nested widget has focus. - SmallMap querystrings; ///< QueryString associated to WWT_EDITBOX widgets. + std::map querystrings; ///< QueryString associated to WWT_EDITBOX widgets. NWidgetBase *nested_root; ///< Root of the nested tree. NWidgetBase **nested_array; ///< Array of pointers into the tree. Do not access directly, use #Window::GetWidget() instead. uint nested_array_size; ///< Size of the nested array.