Skip to content

Commit

Permalink
Codechange: Replaced SmallVector::Get(n) non-const with std::vector::…
Browse files Browse the repository at this point in the history
…data() + n
  • Loading branch information
M3Henry authored and PeterN committed Mar 26, 2019
1 parent bc7dcaf commit aa7ca7f
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/console_cmds.cpp
Expand Up @@ -566,7 +566,7 @@ DEF_CONSOLE_CMD(ConUnBan)
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
IConsolePrint(CC_DEFAULT, msg);
free(_network_ban_list[index]);
_network_ban_list.Erase(_network_ban_list.Get(index));
_network_ban_list.erase(_network_ban_list.begin() + index);
} else {
IConsolePrint(CC_DEFAULT, "Invalid list index or IP not in ban-list.");
IConsolePrint(CC_DEFAULT, "For a list of banned IP's, see the command 'banlist'");
Expand Down
13 changes: 0 additions & 13 deletions src/core/smallvec_type.hpp
Expand Up @@ -180,19 +180,6 @@ class SmallVector : public std::vector<T> {
assert(index <= std::vector<T>::size());
return this->Begin() + index;
}

/**
* Get the pointer to item "number"
*
* @param index the position of the item
* @return the pointer to the item
*/
inline T *Get(uint index)
{
/* Allow access to the 'first invalid' item */
assert(index <= std::vector<T>::size());
return this->Begin() + index;
}
};


Expand Down
2 changes: 1 addition & 1 deletion src/engine_gui.cpp
Expand Up @@ -344,6 +344,6 @@ void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, ui
if (num_items < 2) return;
assert(begin < el->size());
assert(begin + num_items <= el->size());
QSortT(el->Get(begin), num_items, compare);
QSortT(el->data() + begin, num_items, compare);
}

2 changes: 1 addition & 1 deletion src/fios.h
Expand Up @@ -165,7 +165,7 @@ class FileList {
*/
inline FiosItem *Get(uint index)
{
return this->files.Get(index);
return this->files.data() + index;
}

inline const FiosItem &operator[](uint index) const
Expand Down
2 changes: 1 addition & 1 deletion src/linkgraph/linkgraph.cpp
Expand Up @@ -139,7 +139,7 @@ void LinkGraph::RemoveNode(NodeID id)
node_edges[id] = node_edges[last_node];
}
Station::Get(this->nodes[last_node].station)->goods[this->cargo].node = id;
this->nodes.Erase(this->nodes.Get(id));
this->nodes.erase(this->nodes.begin() + id);
this->edges.EraseColumn(id);
/* Not doing EraseRow here, as having the extra invalid row doesn't hurt
* and removing it would trigger a lot of memmove. The data has already
Expand Down
2 changes: 1 addition & 1 deletion src/newgrf.cpp
Expand Up @@ -637,7 +637,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern

/* Reserve the engine slot */
if (!static_access) {
EngineIDMapping *eid = _engine_mngr.Get(engine);
EngineIDMapping *eid = _engine_mngr.data() + engine;
eid->grfid = scope_grfid; // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation
}

Expand Down
4 changes: 2 additions & 2 deletions src/newgrf_config.cpp
Expand Up @@ -262,7 +262,7 @@ GRFParameterInfo::GRFParameterInfo(GRFParameterInfo &info) :
complete_labels(info.complete_labels)
{
for (uint i = 0; i < info.value_names.size(); i++) {
SmallPair<uint32, GRFText *> *data = info.value_names.Get(i);
SmallPair<uint32, GRFText *> *data = info.value_names.data() + i;
this->value_names.Insert(data->first, DuplicateGRFText(data->second));
}
}
Expand All @@ -273,7 +273,7 @@ GRFParameterInfo::~GRFParameterInfo()
CleanUpGRFText(this->name);
CleanUpGRFText(this->desc);
for (uint i = 0; i < this->value_names.size(); i++) {
SmallPair<uint32, GRFText *> *data = this->value_names.Get(i);
SmallPair<uint32, GRFText *> *data = this->value_names.data() + i;
CleanUpGRFText(data->second);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/station_gui.cpp
Expand Up @@ -2133,7 +2133,7 @@ static bool AddNearbyStation(TileIndex tile, void *user_data)

/* First check if there were deleted stations here */
for (uint i = 0; i < _deleted_stations_nearby.size(); i++) {
TileAndStation *ts = _deleted_stations_nearby.Get(i);
TileAndStation *ts = _deleted_stations_nearby.data() + i;
if (ts->tile == tile) {
*_stations_nearby_list.Append() = _deleted_stations_nearby[i].station;
_deleted_stations_nearby.Erase(ts);
Expand Down
4 changes: 2 additions & 2 deletions src/texteff.cpp
Expand Up @@ -50,7 +50,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, Text
}
if (i == _text_effects.size()) _text_effects.Append();

TextEffect *te = _text_effects.Get(i);
TextEffect *te = _text_effects.data() + i;

/* Start defining this object */
te->string_id = msg;
Expand All @@ -69,7 +69,7 @@ TextEffectID AddTextEffect(StringID msg, int center, int y, uint8 duration, Text
void UpdateTextEffect(TextEffectID te_id, StringID msg)
{
/* Update details */
TextEffect *te = _text_effects.Get(te_id);
TextEffect *te = _text_effects.data() + te_id;
if (msg == te->string_id && GetDParam(0) == te->params_1) return;
te->string_id = msg;
te->params_1 = GetDParam(0);
Expand Down

0 comments on commit aa7ca7f

Please sign in to comment.