Skip to content
Permalink
Browse files

Codechange: Replace SmallVector::Length() with std::vector::size()

  • Loading branch information
M3Henry committed Sep 23, 2018
1 parent b1da1aa commit 38cf2f22e8dc0725eb53ca8bacbb934b839e40db
Showing with 282 additions and 292 deletions.
  1. +5 −5 src/autoreplace_gui.cpp
  2. +6 −6 src/bridge_gui.cpp
  3. +6 −6 src/build_vehicle_gui.cpp
  4. +3 −3 src/company_gui.cpp
  5. +3 −3 src/console_cmds.cpp
  6. +1 −1 src/core/pool_func.cpp
  7. +1 −1 src/core/smallstack_type.hpp
  8. +0 −10 src/core/smallvec_type.hpp
  9. +10 −10 src/depot_gui.cpp
  10. +1 −1 src/economy.cpp
  11. +1 −1 src/engine.cpp
  12. +3 −3 src/engine_gui.cpp
  13. +1 −1 src/fios.cpp
  14. +1 −1 src/fios.h
  15. +2 −2 src/game/game_text.cpp
  16. +2 −2 src/gfx.cpp
  17. +4 −4 src/gfx_layout.cpp
  18. +1 −1 src/graph_gui.cpp
  19. +17 −17 src/group_gui.cpp
  20. +1 −1 src/hotkeys.cpp
  21. +1 −1 src/industry_cmd.cpp
  22. +9 −9 src/industry_gui.cpp
  23. +1 −1 src/linkgraph/linkgraph.h
  24. +3 −3 src/music/midifile.cpp
  25. +1 −1 src/network/core/tcp_http.cpp
  26. +2 −2 src/network/core/tcp_listen.h
  27. +2 −2 src/network/core/udp.cpp
  28. +1 −1 src/network/network.cpp
  29. +9 −9 src/network/network_content.cpp
  30. +1 −1 src/network/network_content.h
  31. +7 −7 src/network/network_content_gui.cpp
  32. +12 −12 src/network/network_gui.cpp
  33. +13 −13 src/newgrf.cpp
  34. +2 −2 src/newgrf_cargo.cpp
  35. +6 −6 src/newgrf_config.cpp
  36. +3 −3 src/newgrf_debug_gui.cpp
  37. +1 −1 src/newgrf_engine.cpp
  38. +25 −25 src/newgrf_gui.cpp
  39. +1 −1 src/newgrf_railtype.cpp
  40. +2 −2 src/newgrf_sound.cpp
  41. +1 −1 src/rail_cmd.cpp
  42. +2 −2 src/saveload/animated_tile_sl.cpp
  43. +3 −3 src/saveload/game_sl.cpp
  44. +2 −2 src/saveload/labelmaps_sl.cpp
  45. +2 −2 src/saveload/linkgraph_sl.cpp
  46. +1 −1 src/saveload/saveload.cpp
  47. +1 −1 src/saveload/waypoint_sl.cpp
  48. +1 −1 src/script/api/script_industry.cpp
  49. +3 −3 src/script/squirrel_helper.hpp
  50. +6 −6 src/settings_gui.cpp
  51. +2 −2 src/settingsgen/settingsgen.cpp
  52. +4 −4 src/signs_gui.cpp
  53. +1 −1 src/station_cmd.cpp
  54. +9 −9 src/station_gui.cpp
  55. +9 −9 src/story_gui.cpp
  56. +4 −4 src/strgen/strgen_base.cpp
  57. +2 −2 src/string.cpp
  58. +2 −2 src/stringfilter_type.h
  59. +1 −1 src/strings.cpp
  60. +2 −2 src/texteff.cpp
  61. +5 −5 src/textfile_gui.cpp
  62. +2 −2 src/timetable_cmd.cpp
  63. +5 −5 src/town_gui.cpp
  64. +1 −1 src/train_cmd.cpp
  65. +4 −4 src/train_gui.cpp
  66. +4 −4 src/vehicle_cmd.cpp
  67. +22 −22 src/vehicle_gui.cpp
  68. +4 −4 src/viewport.cpp
  69. +5 −5 src/widgets/dropdown.cpp
  70. +1 −1 src/window.cpp
@@ -160,8 +160,8 @@ class ReplaceVehicleWindow : public Window {
if (this->engines[0].NeedRebuild()) {
/* We need to rebuild the left engines list */
this->GenerateReplaceVehList(true);
this->vscroll[0]->SetCount(this->engines[0].Length());
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].Length() != 0) {
this->vscroll[0]->SetCount(this->engines[0].size());
if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) {
this->sel_engine[0] = this->engines[0][0];
}
}
@@ -180,7 +180,7 @@ class ReplaceVehicleWindow : public Window {
}
/* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
this->GenerateReplaceVehList(false);
this->vscroll[1]->SetCount(this->engines[1].Length());
this->vscroll[1]->SetCount(this->engines[1].size());
if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
int position = 0;
for (EngineID *it = this->engines[1].Begin(); it != this->engines[1].End(); ++it) {
@@ -384,7 +384,7 @@ class ReplaceVehicleWindow : public Window {
case WID_RV_RIGHT_MATRIX: {
int side = (widget == WID_RV_LEFT_MATRIX) ? 0 : 1;
EngineID start = this->vscroll[side]->GetPosition(); // what is the offset for the start (scrolling)
EngineID end = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].Length());
EngineID end = min(this->vscroll[side]->GetCapacity() + start, this->engines[side].size());

/* Do the actual drawing */
DrawEngineList((VehicleType)this->window_number, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP,
@@ -501,7 +501,7 @@ class ReplaceVehicleWindow : public Window {
click_side = 1;
}
uint i = this->vscroll[click_side]->GetScrolledRowFromWidget(pt.y, this, widget);
size_t engine_count = this->engines[click_side].Length();
size_t engine_count = this->engines[click_side].size();

EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
@@ -153,7 +153,7 @@ class BuildBridgeWindow : public Window {
this->bridges->NeedResort();
this->SortBridgeList();

this->vscroll->SetCount(bl->Length());
this->vscroll->SetCount(bl->size());
}

~BuildBridgeWindow()
@@ -186,7 +186,7 @@ class BuildBridgeWindow : public Window {
case WID_BBS_BRIDGE_LIST: {
Dimension sprite_dim = {0, 0}; // Biggest bridge sprite dimension
Dimension text_dim = {0, 0}; // Biggest text dimension
for (int i = 0; i < (int)this->bridges->Length(); i++) {
for (int i = 0; i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->Get(i)->spec;
sprite_dim = maxdim(sprite_dim, GetSpriteSize(b->sprite));

@@ -226,7 +226,7 @@ class BuildBridgeWindow : public Window {

case WID_BBS_BRIDGE_LIST: {
uint y = r.top;
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->Length(); i++) {
for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < (int)this->bridges->size(); i++) {
const BridgeSpec *b = this->bridges->Get(i)->spec;

SetDParam(2, this->bridges->Get(i)->cost);
@@ -246,7 +246,7 @@ class BuildBridgeWindow : public Window {
virtual EventState OnKeyPress(WChar key, uint16 keycode)
{
const uint8 i = keycode - '1';
if (i < 9 && i < this->bridges->Length()) {
if (i < 9 && i < this->bridges->size()) {
/* Build the requested bridge */
this->BuildBridge(i);
delete this;
@@ -261,7 +261,7 @@ class BuildBridgeWindow : public Window {
default: break;
case WID_BBS_BRIDGE_LIST: {
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BBS_BRIDGE_LIST);
if (i < this->bridges->Length()) {
if (i < this->bridges->size()) {
this->BuildBridge(i);
delete this;
}
@@ -426,7 +426,7 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo
}
}

if (bl != NULL && bl->Length() != 0) {
if (bl != NULL && bl->size() != 0) {
new BuildBridgeWindow(&_build_bridge_desc, start, end, type, bl);
} else {
delete bl;
@@ -896,7 +896,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
static const int sprite_y_offsets[] = { -1, -1, -2, -2 };

/* Obligatory sanity checks! */
assert(max <= eng_list->Length());
assert(max <= eng_list->size());

bool rtl = _current_text_dir == TD_RTL;
int step_size = GetEngineListHeight(type);
@@ -1053,7 +1053,7 @@ struct BuildVehicleWindow : Window {
this->eng_list.ForceRebuild();
this->GenerateBuildList(); // generate the list, since we need it in the next line
/* Select the first engine in the list as default when opening the window */
if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0];
if (this->eng_list.size() > 0) this->sel_engine = this->eng_list[0];
}

/** Populate the filter list and set the cargo filter criteria. */
@@ -1109,7 +1109,7 @@ struct BuildVehicleWindow : Window {
void FilterEngineList()
{
this->eng_list.Filter(this->cargo_filter[this->cargo_filter_criteria]);
if (0 == this->eng_list.Length()) { // no engine passed through the filter, invalidate the previously selected engine
if (0 == this->eng_list.size()) { // no engine passed through the filter, invalidate the previously selected engine
this->sel_engine = INVALID_ENGINE;
} else if (!this->eng_list.Contains(this->sel_engine)) { // previously selected engine didn't pass the filter, select the first engine of the list
this->sel_engine = this->eng_list[0];
@@ -1292,7 +1292,7 @@ struct BuildVehicleWindow : Window {

case WID_BV_LIST: {
uint i = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_BV_LIST);
size_t num_items = this->eng_list.Length();
size_t num_items = this->eng_list.size();
this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
this->SetDirty();
if (_ctrl_pressed) {
@@ -1424,7 +1424,7 @@ struct BuildVehicleWindow : Window {
{
switch (widget) {
case WID_BV_LIST:
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.Length()), this->sel_engine, false, DEFAULT_GROUP);
DrawEngineList(this->vehicle_type, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, &this->eng_list, this->vscroll->GetPosition(), min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->eng_list.size()), this->sel_engine, false, DEFAULT_GROUP);
break;

case WID_BV_SORT_ASCENDING_DESCENDING:
@@ -1436,7 +1436,7 @@ struct BuildVehicleWindow : Window {
virtual void OnPaint()
{
this->GenerateBuildList();
this->vscroll->SetCount(this->eng_list.Length());
this->vscroll->SetCount(this->eng_list.size());

this->SetWidgetDisabledState(WID_BV_SHOW_HIDE, this->sel_engine == INVALID_ENGINE);

@@ -688,7 +688,7 @@ struct SelectCompanyLiveryWindow : public Window {
}
}
} else {
this->rows = this->groups.Length();
this->rows = this->groups.size();
}

this->vscroll->SetCount(this->rows);
@@ -904,7 +904,7 @@ struct SelectCompanyLiveryWindow : public Window {
}
}
} else {
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->groups.Length());
uint max = min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->groups.size());
for (uint i = this->vscroll->GetPosition(); i < max; ++i) {
const Group *g = this->groups[i];
SetDParam(0, g->index);
@@ -944,7 +944,7 @@ struct SelectCompanyLiveryWindow : public Window {
this->groups.ForceRebuild();
this->BuildGroupList((CompanyID)this->window_number);

if (this->groups.Length() > 0) {
if (this->groups.size() > 0) {
this->sel = this->groups[0]->index;
}
}
@@ -563,16 +563,16 @@ DEF_CONSOLE_CMD(ConUnBan)

/* Try by IP. */
uint index;
for (index = 0; index < _network_ban_list.Length(); index++) {
for (index = 0; index < _network_ban_list.size(); index++) {
if (strcmp(_network_ban_list[index], argv[1]) == 0) break;
}

/* Try by index. */
if (index >= _network_ban_list.Length()) {
if (index >= _network_ban_list.size()) {
index = atoi(argv[1]) - 1U; // let it wrap
}

if (index < _network_ban_list.Length()) {
if (index < _network_ban_list.size()) {
char msg[64];
seprintf(msg, lastof(msg), "Unbanned %s", _network_ban_list[index]);
IConsolePrint(CC_DEFAULT, msg);
@@ -22,7 +22,7 @@
{
PoolVector *pools = PoolBase::GetPools();
pools->Erase(pools->Find(this));
if (pools->Length() == 0) delete pools;
if (pools->size() == 0) delete pools;
}

/**
@@ -73,7 +73,7 @@ class SimplePool {
if (!this->data[index].valid) return index;
}

if (index >= this->data.Length() && index < Tmax_size) {
if (index >= this->data.size() && index < Tmax_size) {
this->data.Resize(index + 1);
}
return index;
@@ -217,16 +217,6 @@ class SmallVector : public std::vector<T> {
return is_member;
}

/**
* Get the number of items in the list.
*
* @return The number of items in the list.
*/
inline uint Length() const
{
return std::vector<T>::size();
}

/**
* Get the pointer to the first item (const)
*
@@ -398,7 +398,7 @@ struct DepotWindow : Window {
uint16 rows_in_display = wid->current_y / wid->resize_y;

uint16 num = this->vscroll->GetPosition() * this->num_columns;
int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * this->num_columns));
int maxval = min(this->vehicle_list.size(), num + (rows_in_display * this->num_columns));
int y;
for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
for (byte i = 0; i < this->num_columns && num < maxval; i++, num++) {
@@ -413,11 +413,11 @@ struct DepotWindow : Window {
}
}

maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns));
maxval = min(this->vehicle_list.size() + this->wagon_list.size(), (this->vscroll->GetPosition() * this->num_columns) + (rows_in_display * this->num_columns));

/* Draw the train wagons without an engine in front. */
for (; num < maxval; num++, y += this->resize.step_height) {
const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
const Vehicle *v = this->wagon_list[num - this->vehicle_list.size()];
this->DrawVehicleInDepot(v, r.left, r.right, y);
}
}
@@ -465,7 +465,7 @@ struct DepotWindow : Window {

uint pos = ((row + this->vscroll->GetPosition()) * this->num_columns) + xt;

if (this->vehicle_list.Length() + this->wagon_list.Length() <= pos) {
if (this->vehicle_list.size() + this->wagon_list.size() <= pos) {
/* Clicking on 'line' / 'block' without a vehicle */
if (this->type == VEH_TRAIN) {
/* End the dragging */
@@ -478,12 +478,12 @@ struct DepotWindow : Window {
}

bool wagon = false;
if (this->vehicle_list.Length() > pos) {
if (this->vehicle_list.size() > pos) {
*veh = this->vehicle_list[pos];
/* Skip vehicles that are scrolled off the list */
if (this->type == VEH_TRAIN) x += this->hscroll->GetPosition();
} else {
pos -= this->vehicle_list.Length();
pos -= this->vehicle_list.size();
*veh = this->wagon_list[pos];
/* free wagons don't have an initial loco. */
x -= ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
@@ -726,19 +726,19 @@ struct DepotWindow : Window {
/* determine amount of items for scroller */
if (this->type == VEH_TRAIN) {
uint max_width = ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
for (uint num = 0; num < this->vehicle_list.Length(); num++) {
for (uint num = 0; num < this->vehicle_list.size(); num++) {
uint width = 0;
for (const Train *v = Train::From(this->vehicle_list[num]); v != NULL; v = v->Next()) {
width += v->GetDisplayImageWidth();
}
max_width = max(max_width, width);
}
/* Always have 1 empty row, so people can change the setting of the train */
this->vscroll->SetCount(this->vehicle_list.Length() + this->wagon_list.Length() + 1);
this->vscroll->SetCount(this->vehicle_list.size() + this->wagon_list.size() + 1);
/* Always make it longer than the longest train, so you can attach vehicles at the end, and also see the next vertical tile separator line */
this->hscroll->SetCount(max_width + ScaleGUITrad(2 * VEHICLEINFO_FULL_VEHICLE_WIDTH + 1));
} else {
this->vscroll->SetCount(CeilDiv(this->vehicle_list.Length(), this->num_columns));
this->vscroll->SetCount(CeilDiv(this->vehicle_list.size(), this->num_columns));
}

/* Setup disabled buttons. */
@@ -811,7 +811,7 @@ struct DepotWindow : Window {

case WID_D_SELL_ALL:
/* Only open the confirmation window if there are anything to sell */
if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) {
if (this->vehicle_list.size() != 0 || this->wagon_list.size() != 0) {
TileIndex tile = this->window_number;
byte vehtype = this->type;

@@ -1043,7 +1043,7 @@ static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint n

uint accepted = 0;

for (uint i = 0; i < st->industries_near.Length() && num_pieces != 0; i++) {
for (uint i = 0; i < st->industries_near.size() && num_pieces != 0; i++) {
Industry *ind = st->industries_near[i];
if (ind->index == source) continue;

@@ -547,7 +547,7 @@ void SetupEngines()
DeleteWindowByClass(WC_ENGINE_PREVIEW);
_engine_pool.CleanPool();

assert(_engine_mngr.Length() >= _engine_mngr.NUM_DEFAULT_ENGINES);
assert(_engine_mngr.size() >= _engine_mngr.NUM_DEFAULT_ENGINES);
const EngineIDMapping *end = _engine_mngr.End();
uint index = 0;
for (const EngineIDMapping *eid = _engine_mngr.Begin(); eid != end; eid++, index++) {
@@ -325,7 +325,7 @@ void DrawVehicleEngine(int left, int right, int preferred_x, int y, EngineID eng
*/
void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
{
uint size = el->Length();
uint size = el->size();
/* out-of-bounds access at the next line for size == 0 (even with operator[] at some systems)
* generally, do not sort if there are less than 2 items */
if (size < 2) return;
@@ -342,8 +342,8 @@ void EngList_Sort(GUIEngineList *el, EngList_SortTypeFunction compare)
void EngList_SortPartial(GUIEngineList *el, EngList_SortTypeFunction compare, uint begin, uint num_items)
{
if (num_items < 2) return;
assert(begin < el->Length());
assert(begin + num_items <= el->Length());
assert(begin < el->size());
assert(begin + num_items <= el->size());
QSortT(el->Get(begin), num_items, compare);
}

@@ -397,7 +397,7 @@ static void FiosGetFileList(SaveLoadOperation fop, fios_getlist_callback_proc *c
{
SortingBits order = _savegame_sort_order;
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
QSortT(file_list.files.Begin(), file_list.files.Length(), CompareFiosItems);
QSortT(file_list.files.Begin(), file_list.files.size(), CompareFiosItems);
_savegame_sort_order = order;
}

@@ -129,7 +129,7 @@ class FileList {
*/
inline uint Length() const
{
return this->files.Length();
return this->files.size();
}

/**
@@ -212,7 +212,7 @@ struct StringNameWriter : HeaderWriter {

void WriteStringID(const char *name, int stringid)
{
if (stringid == (int)this->strings->Length()) *this->strings->Append() = stredup(name);
if (stringid == (int)this->strings->size()) *this->strings->Append() = stredup(name);
}

void Finalise(const StringData &data)
@@ -340,7 +340,7 @@ GameStrings *_current_data = NULL;
*/
const char *GetGameStringPtr(uint id)
{
if (id >= _current_data->cur_language->lines.Length()) return GetStringPtr(STR_UNDEFINED);
if (id >= _current_data->cur_language->lines.size()) return GetStringPtr(STR_UNDEFINED);
return _current_data->cur_language->lines[id];
}

@@ -510,7 +510,7 @@ int DrawString(int left, int right, int top, const char *str, TextColour colour,
}

Layouter layout(str, INT32_MAX, colour, fontsize);
if (layout.Length() == 0) return 0;
if (layout.size() == 0) return 0;

return DrawLayoutLine(*layout.Begin(), top, left, right, align, underline, true);
}
@@ -575,7 +575,7 @@ int GetStringLineCount(StringID str, int maxw)
GetString(buffer, str, lastof(buffer));

Layouter layout(buffer, maxw);
return layout.Length();
return layout.size();
}

/**

0 comments on commit 38cf2f2

Please sign in to comment.
You can’t perform that action at this time.