Skip to content

Commit

Permalink
Codechange: Removed SmallVector completely
Browse files Browse the repository at this point in the history
  • Loading branch information
M3Henry authored and PeterN committed Mar 26, 2019
1 parent 6570f79 commit c01a2e2
Show file tree
Hide file tree
Showing 69 changed files with 109 additions and 127 deletions.
2 changes: 1 addition & 1 deletion src/animated_tile.cpp
Expand Up @@ -19,7 +19,7 @@
#include "safeguards.h"

/** The table/list with animated tiles. */
SmallVector<TileIndex, 256> _animated_tiles;
std::vector<TileIndex> _animated_tiles;

/**
* Removes the given tile from the animated tile table.
Expand Down
2 changes: 1 addition & 1 deletion src/company_gui.cpp
Expand Up @@ -562,7 +562,7 @@ struct SelectCompanyLiveryWindow : public Window {
uint rows;
uint line_height;
GUIGroupList groups;
SmallVector<int, 32> indents;
std::vector<int> indents;
Scrollbar *vscroll;

void ShowColourDropDownMenu(uint32 widget)
Expand Down
2 changes: 1 addition & 1 deletion src/core/pool_type.hpp
Expand Up @@ -26,7 +26,7 @@ enum PoolType {
};
DECLARE_ENUM_AS_BIT_SET(PoolType)

typedef SmallVector<struct PoolBase *, 4> PoolVector; ///< Vector of pointers to PoolBase
typedef std::vector<struct PoolBase *> PoolVector; ///< Vector of pointers to PoolBase

/** Base class for base of all pools. */
struct PoolBase {
Expand Down
2 changes: 1 addition & 1 deletion src/core/smallmap_type.hpp
Expand Up @@ -40,7 +40,7 @@ struct SmallPair {
* @see SmallVector
*/
template <typename T, typename U, uint S = 16>
struct SmallMap : SmallVector<SmallPair<T, U>, S> {
struct SmallMap : std::vector<SmallPair<T, U> > {
typedef ::SmallPair<T, U> Pair;
typedef Pair *iterator;
typedef const Pair *const_iterator;
Expand Down
2 changes: 1 addition & 1 deletion src/core/smallstack_type.hpp
Expand Up @@ -87,7 +87,7 @@ class SimplePool {
Tindex first_free;

ThreadMutex *mutex;
SmallVector<SimplePoolPoolItem, Tgrowth_step> data;
std::vector<SimplePoolPoolItem> data;
};

/**
Expand Down
27 changes: 5 additions & 22 deletions src/core/smallvec_type.hpp
Expand Up @@ -34,22 +34,6 @@ inline bool include(std::vector<T>& vec, const T &item)
return is_member;
}


/**
* Simple vector template class.
*
* @note There are no asserts in the class so you have
* to care about that you grab an item which is
* inside the list.
*
* @tparam T The type of the items stored
* @tparam S The steps of allocation
*/


template <typename T, uint S>
using SmallVector = std::vector<T>;

/**
* Helper function to get the index of an item
* Consider using std::set, std::unordered_set or std::flat_set in new code
Expand All @@ -73,19 +57,18 @@ int find_index(std::vector<T> const& vec, T const& item)
* Consider using std::back_inserter in new code
*
* @param vec A reference to the vector to be extended
* @param num The number of elements to default-construct
* @param num Number of elements to be default-constructed
*
* @return Pointer to the first new element
*/
template <typename T>
inline T* grow(std::vector<T>& vec, std::size_t num)
T* grow(std::vector<T>& vec, std::size_t num)
{
const std::size_t pos = vec.size();
std::size_t const pos = vec.size();
vec.resize(pos + num);
return vec.data() + pos;
}


/**
* Simple vector template class, with automatic free.
*
Expand All @@ -97,7 +80,7 @@ inline T* grow(std::vector<T>& vec, std::size_t num)
* @param S The steps of allocation
*/
template <typename T, uint S>
class AutoFreeSmallVector : public SmallVector<T, S> {
class AutoFreeSmallVector : public std::vector<T> {
public:
~AutoFreeSmallVector()
{
Expand Down Expand Up @@ -128,7 +111,7 @@ class AutoFreeSmallVector : public SmallVector<T, S> {
* @param S The steps of allocation
*/
template <typename T, uint S>
class AutoDeleteSmallVector : public SmallVector<T, S> {
class AutoDeleteSmallVector : public std::vector<T> {
public:
~AutoDeleteSmallVector()
{
Expand Down
2 changes: 1 addition & 1 deletion src/economy.cpp
Expand Up @@ -77,7 +77,7 @@ static inline int32 BigMulS(const int32 a, const int32 b, const uint8 shift)
return (int32)((int64)a * (int64)b >> shift);
}

typedef SmallVector<Industry *, 16> SmallIndustryList;
typedef std::vector<Industry *> SmallIndustryList;

/**
* Score info, values used for computing the detailed performance rating.
Expand Down
2 changes: 1 addition & 1 deletion src/engine_base.h
Expand Up @@ -156,7 +156,7 @@ struct EngineIDMapping {
* Stores the mapping of EngineID to the internal id of newgrfs.
* Note: This is not part of Engine, as the data in the EngineOverrideManager and the engine pool get resetted in different cases.
*/
struct EngineOverrideManager : SmallVector<EngineIDMapping, 256> {
struct EngineOverrideManager : std::vector<EngineIDMapping> {
static const uint NUM_DEFAULT_ENGINES; ///< Number of default entries

void ResetToDefaultMapping();
Expand Down
2 changes: 1 addition & 1 deletion src/fios.cpp
Expand Up @@ -655,7 +655,7 @@ struct ScenarioIdentifier {
/**
* Scanner to find the unique IDs of scenarios
*/
class ScenarioScanner : protected FileScanner, public SmallVector<ScenarioIdentifier, 8> {
class ScenarioScanner : protected FileScanner, public std::vector<ScenarioIdentifier> {
bool scanned; ///< Whether we've already scanned
public:
/** Initialise */
Expand Down
2 changes: 1 addition & 1 deletion src/fios.h
Expand Up @@ -198,7 +198,7 @@ class FileList {
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
const FiosItem *FindItem(const char *file);

SmallVector<FiosItem, 32> files; ///< The list of files.
std::vector<FiosItem> files; ///< The list of files.
};

enum SortingBits {
Expand Down
2 changes: 1 addition & 1 deletion src/group_gui.cpp
Expand Up @@ -121,7 +121,7 @@ class VehicleGroupWindow : public BaseVehicleListWindow {
uint tiny_step_height; ///< Step height for the group list
Scrollbar *group_sb;

SmallVector<int, 16> indents; ///< Indentation levels
std::vector<int> indents; ///< Indentation levels

Dimension column_size[VGC_END]; ///< Size of the columns in the group list.

Expand Down
4 changes: 2 additions & 2 deletions src/hotkeys.cpp
Expand Up @@ -24,7 +24,7 @@ char *_hotkeys_file;
* List of all HotkeyLists.
* This is a pointer to ensure initialisation order with the various static HotkeyList instances.
*/
static SmallVector<HotkeyList*, 16> *_hotkey_lists = NULL;
static std::vector<HotkeyList*> *_hotkey_lists = NULL;

/** String representation of a keycode */
struct KeycodeNames {
Expand Down Expand Up @@ -254,7 +254,7 @@ void Hotkey::AddKeycode(uint16 keycode)
HotkeyList::HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler) :
global_hotkey_handler(global_hotkey_handler), ini_group(ini_group), items(items)
{
if (_hotkey_lists == NULL) _hotkey_lists = new SmallVector<HotkeyList*, 16>();
if (_hotkey_lists == NULL) _hotkey_lists = new std::vector<HotkeyList*>();
_hotkey_lists->push_back(this);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotkeys.h
Expand Up @@ -29,7 +29,7 @@ struct Hotkey {

const char *name;
int num;
SmallVector<uint16, 1> keycodes;
std::vector<uint16> keycodes;
};

#define HOTKEY_LIST_END Hotkey((uint16)0, NULL, -1)
Expand Down
2 changes: 1 addition & 1 deletion src/industry_cmd.cpp
Expand Up @@ -1884,7 +1884,7 @@ static CommandCost CreateNewIndustryHelper(TileIndex tile, IndustryType type, Do

*ip = NULL;

SmallVector<ClearedObjectArea, 1> object_areas(_cleared_object_areas);
std::vector<ClearedObjectArea> object_areas(_cleared_object_areas);
CommandCost ret = CheckIfIndustryTilesAreFree(tile, it, itspec_index, type, random_initial_bits, founder, creation_type, &custom_shape_check);
_cleared_object_areas = object_areas;
if (ret.Failed()) return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/industry_gui.cpp
Expand Up @@ -2155,7 +2155,7 @@ next_cargo: ;
struct IndustryCargoesWindow : public Window {
static const int HOR_TEXT_PADDING, VERT_TEXT_PADDING;

typedef SmallVector<CargoesRow, 4> Fields;
typedef std::vector<CargoesRow> Fields;

Fields fields; ///< Fields to display in the #WID_IC_PANEL.
uint ind_cargo; ///< If less than #NUM_INDUSTRYTYPES, an industry type, else a cargo id + NUM_INDUSTRYTYPES.
Expand Down
2 changes: 1 addition & 1 deletion src/language.h
Expand Up @@ -96,7 +96,7 @@ struct LanguageMetadata : public LanguagePackHeader {
};

/** Type for the list of language meta data. */
typedef SmallVector<LanguageMetadata, 4> LanguageList;
typedef std::vector<LanguageMetadata> LanguageList;

/** The actual list of language meta data. */
extern LanguageList _languages;
Expand Down
2 changes: 1 addition & 1 deletion src/linkgraph/linkgraph.h
Expand Up @@ -435,7 +435,7 @@ class LinkGraph : public LinkGraphPool::PoolItem<&_link_graph_pool> {
void RemoveEdge(NodeID to);
};

typedef SmallVector<BaseNode, 16> NodeVector;
typedef std::vector<BaseNode> NodeVector;
typedef SmallMatrix<BaseEdge> EdgeMatrix;

/** Minimum effective distance for timeout calculation. */
Expand Down
2 changes: 1 addition & 1 deletion src/linkgraph/linkgraphjob.h
Expand Up @@ -50,7 +50,7 @@ class LinkGraphJob : public LinkGraphJobPool::PoolItem<&_link_graph_job_pool>{
void Init(uint supply);
};

typedef SmallVector<NodeAnnotation, 16> NodeAnnotationVector;
typedef std::vector<NodeAnnotation> NodeAnnotationVector;
typedef SmallMatrix<EdgeAnnotation> EdgeAnnotationMatrix;

friend const SaveLoad *GetLinkGraphJobDesc();
Expand Down
2 changes: 1 addition & 1 deletion src/music/midifile.hpp
Expand Up @@ -24,7 +24,7 @@ struct MidiFile {
struct DataBlock {
uint32 ticktime; ///< tick number since start of file this block should be triggered at
uint32 realtime; ///< real-time (microseconds) since start of file this block should be triggered at
SmallVector<byte, 8> data; ///< raw midi data contained in block
std::vector<byte> data; ///< raw midi data contained in block
DataBlock(uint32 _ticktime = 0) : ticktime(_ticktime) { }
};
struct TempoChange {
Expand Down
2 changes: 1 addition & 1 deletion src/network/core/address.h
Expand Up @@ -18,7 +18,7 @@
#include "../../core/smallmap_type.hpp"

class NetworkAddress;
typedef SmallVector<NetworkAddress, 4> NetworkAddressList; ///< Type for a list of addresses.
typedef std::vector<NetworkAddress> NetworkAddressList; ///< Type for a list of addresses.
typedef SmallMap<NetworkAddress, SOCKET, 4> SocketList; ///< Type for a mapping between address and socket.

/**
Expand Down
2 changes: 1 addition & 1 deletion src/network/core/tcp_connect.cpp
Expand Up @@ -19,7 +19,7 @@
#include "../../safeguards.h"

/** List of connections that are currently being created */
static SmallVector<TCPConnecter *, 1> _tcp_connecters;
static std::vector<TCPConnecter *> _tcp_connecters;

/**
* Create a new connecter for the given address
Expand Down
2 changes: 1 addition & 1 deletion src/network/core/tcp_http.cpp
Expand Up @@ -21,7 +21,7 @@
#include "../../safeguards.h"

/** List of open HTTP connections. */
static SmallVector<NetworkHTTPSocketHandler *, 1> _http_connections;
static std::vector<NetworkHTTPSocketHandler *> _http_connections;

/**
* Start the querying
Expand Down
10 changes: 5 additions & 5 deletions src/network/network_content.h
Expand Up @@ -16,9 +16,9 @@
#include "core/tcp_http.h"

/** Vector with content info */
typedef SmallVector<ContentInfo *, 16> ContentVector;
typedef std::vector<ContentInfo *> ContentVector;
/** Vector with constant content info */
typedef SmallVector<const ContentInfo *, 16> ConstContentVector;
typedef std::vector<const ContentInfo *> ConstContentVector;

/** Iterator for the content vector */
typedef ContentInfo **ContentIterator;
Expand Down Expand Up @@ -66,11 +66,11 @@ struct ContentCallback {
*/
class ClientNetworkContentSocketHandler : public NetworkContentSocketHandler, ContentCallback, HTTPCallback {
protected:
typedef SmallVector<ContentID, 4> ContentIDList; ///< List of content IDs to (possibly) select.
SmallVector<ContentCallback *, 2> callbacks; ///< Callbacks to notify "the world"
typedef std::vector<ContentID> ContentIDList; ///< List of content IDs to (possibly) select.
std::vector<ContentCallback *> callbacks; ///< Callbacks to notify "the world"
ContentIDList requested; ///< ContentIDs we already requested (so we don't do it again)
ContentVector infos; ///< All content info we received
SmallVector<char, 1024> http_response; ///< The HTTP response to the requests we've been doing
std::vector<char> http_response; ///< The HTTP response to the requests we've been doing
int http_response_index; ///< Where we are, in the response, with handling it

FILE *curFile; ///< Currently downloaded file
Expand Down
2 changes: 1 addition & 1 deletion src/network/network_content_gui.cpp
Expand Up @@ -160,7 +160,7 @@ void BaseNetworkContentDownloadStatusWindow::OnDownloadProgress(const ContentInf
/** Window for showing the download status of content */
struct NetworkContentDownloadStatusWindow : public BaseNetworkContentDownloadStatusWindow {
private:
SmallVector<ContentType, 4> receivedTypes; ///< Types we received so we can update their cache
std::vector<ContentType> receivedTypes; ///< Types we received so we can update their cache

public:
/**
Expand Down
2 changes: 1 addition & 1 deletion src/network/network_gui.cpp
Expand Up @@ -1728,7 +1728,7 @@ struct NetworkClientListPopupWindow : Window {
uint sel_index;
ClientID client_id;
Point desired_location;
SmallVector<ClientListAction, 2> actions; ///< Actions to execute
std::vector<ClientListAction> actions; ///< Actions to execute

/**
* Add an action to the list of actions to execute.
Expand Down
8 changes: 4 additions & 4 deletions src/newgrf.cpp
Expand Up @@ -65,7 +65,7 @@
* served as subject to the initial testing of this codec. */

/** List of all loaded GRF files */
static SmallVector<GRFFile *, 16> _grf_files;
static std::vector<GRFFile *> _grf_files;

/** Miscellaneous GRF features, set by Action 0x0D, parameter 0x9E */
byte _misc_grf_features = 0;
Expand Down Expand Up @@ -459,7 +459,7 @@ struct StringIDMapping {
StringID source; ///< Source StringID (GRF local).
StringID *target; ///< Destination for mapping result.
};
typedef SmallVector<StringIDMapping, 16> StringIDMappingVector;
typedef std::vector<StringIDMapping> StringIDMappingVector;
static StringIDMappingVector _string_to_grf_mapping;

/**
Expand Down Expand Up @@ -1901,7 +1901,7 @@ static ChangeInfoResult StationChangeInfo(uint stid, int numinfo, int prop, Byte
/* On error, bail out immediately. Temporary GRF data was already freed */
if (_cur.skip_sprites < 0) return CIR_DISABLED;

static SmallVector<DrawTileSeqStruct, 8> tmp_layout;
static std::vector<DrawTileSeqStruct> tmp_layout;
tmp_layout.clear();
for (;;) {
/* no relative bounding box support */
Expand Down Expand Up @@ -4787,7 +4787,7 @@ static void NewSpriteGroup(ByteReader *buf)
case 2: group->size = DSG_SIZE_DWORD; varsize = 4; break;
}

static SmallVector<DeterministicSpriteGroupAdjust, 16> adjusts;
static std::vector<DeterministicSpriteGroupAdjust> adjusts;
adjusts.clear();

/* Loop through the var adjusts. Unfortunately we don't know how many we have
Expand Down
4 changes: 2 additions & 2 deletions src/newgrf.h
Expand Up @@ -122,10 +122,10 @@ struct GRFFile : ZeroedMemoryAllocator {

GRFLabel *label; ///< Pointer to the first label. This is a linked list, not an array.

SmallVector<CargoLabel, 4> cargo_list; ///< Cargo translation table (local ID -> label)
std::vector<CargoLabel> cargo_list; ///< Cargo translation table (local ID -> label)
uint8 cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID)

SmallVector<RailTypeLabel, 4> railtype_list; ///< Railtype translation table
std::vector<RailTypeLabel> railtype_list; ///< Railtype translation table
RailTypeByte railtype_map[RAILTYPE_END];

CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_commons.cpp
Expand Up @@ -579,7 +579,7 @@ bool Convert8bitBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_r
}


/* static */ SmallVector<DrawTileSeqStruct, 8> NewGRFSpriteLayout::result_seq;
/* static */ std::vector<DrawTileSeqStruct> NewGRFSpriteLayout::result_seq;

/**
* Clone the building sprites of a spritelayout.
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_commons.h
Expand Up @@ -170,7 +170,7 @@ struct NewGRFSpriteLayout : ZeroedMemoryAllocator, DrawTileSprites {
}

private:
static SmallVector<DrawTileSeqStruct, 8> result_seq; ///< Temporary storage when preprocessing spritelayouts.
static std::vector<DrawTileSeqStruct> result_seq; ///< Temporary storage when preprocessing spritelayouts.
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_config.h
Expand Up @@ -172,7 +172,7 @@ struct GRFConfig : ZeroedMemoryAllocator {
uint8 num_params; ///< Number of used parameters
uint8 num_valid_params; ///< NOSAVE: Number of valid parameters (action 0x14)
uint8 palette; ///< GRFPalette, bitset
SmallVector<GRFParameterInfo *, 4> param_info; ///< NOSAVE: extra information about the parameters
std::vector<GRFParameterInfo *> param_info; ///< NOSAVE: extra information about the parameters
bool has_param_defaults; ///< NOSAVE: did this newgrf specify any defaults for it's parameters

struct GRFConfig *next; ///< NOSAVE: Next item in the linked list
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf_debug.h
Expand Up @@ -29,7 +29,7 @@ struct NewGrfDebugSpritePicker {
NewGrfDebugSpritePickerMode mode; ///< Current state
void *clicked_pixel; ///< Clicked pixel (pointer to blitter buffer)
uint32 click_time; ///< Realtime tick when clicked to detect next frame
SmallVector<SpriteID, 256> sprites; ///< Sprites found
std::vector<SpriteID> sprites; ///< Sprites found
};

extern NewGrfDebugSpritePicker _newgrf_debug_sprite_picker;
Expand Down

0 comments on commit c01a2e2

Please sign in to comment.