GunChleoc has proposed merging
lp:~widelands-dev/widelands/const_portdock_fleet_and_ship_functions into
lp:widelands.
Commit message:
Made as many functions as possible const in portdock, fleet and ship and
followed the snowball effect
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/const_portdock_fleet_and_ship_functions/+merge/354301
const functions give the compiler more room for optimization.
--
Your team Widelands Developers is requested to review the proposed merge of
lp:~widelands-dev/widelands/const_portdock_fleet_and_ship_functions into
lp:widelands.
=== modified file 'src/ai/defaultai_seafaring.cc'
--- src/ai/defaultai_seafaring.cc 2018-08-16 16:10:43 +
+++ src/ai/defaultai_seafaring.cc 2018-09-05 07:39:19 +
@@ -126,7 +126,7 @@
for (const WarehouseSiteObserver& wh_obs : warehousesites) {
if (wh_obs.bo->is(BuildingAttribute::kPort)) {
ports_count += 1;
- if (Widelands::PortDock* pd = wh_obs.site->get_portdock()) {
+ if (const Widelands::PortDock* pd = wh_obs.site->get_portdock()) {
if (pd->expedition_started()) {
expeditions_in_prep += 1;
}
=== modified file 'src/economy/flag.cc'
--- src/economy/flag.cc 2018-08-09 11:11:15 +
+++ src/economy/flag.cc 2018-09-05 07:39:19 +
@@ -967,7 +967,7 @@
flag.molog("BUG: flag_job_request_callback: worker not found in list\n");
}
-void Flag::log_general_info(const Widelands::EditorGameBase& egbase) {
+void Flag::log_general_info(const Widelands::EditorGameBase& egbase) const {
molog("Flag at %i,%i\n", position_.x, position_.y);
Widelands::PlayerImmovable::log_general_info(egbase);
=== modified file 'src/economy/flag.h'
--- src/economy/flag.h 2018-08-09 11:11:15 +
+++ src/economy/flag.h 2018-09-05 07:39:19 +
@@ -163,7 +163,7 @@
void add_flag_job(Game&, DescriptionIndex workerware, const std::string& programname);
- void log_general_info(const EditorGameBase&) override;
+ void log_general_info(const EditorGameBase&) const override;
protected:
bool init(EditorGameBase&) override;
=== modified file 'src/economy/fleet.cc'
--- src/economy/fleet.cc 2018-04-07 16:59:00 +
+++ src/economy/fleet.cc 2018-09-05 07:39:19 +
@@ -324,11 +324,11 @@
return true;
}
-uint32_t Fleet::count_ships() {
+uint32_t Fleet::count_ships() const {
return ships_.size();
}
-uint32_t Fleet::count_ships_heading_here(EditorGameBase& egbase, PortDock* port) {
+uint32_t Fleet::count_ships_heading_here(EditorGameBase& egbase, PortDock* port) const {
uint32_t ships_on_way = 0;
for (uint16_t s = 0; s < ships_.size(); s += 1) {
if (ships_[s]->get_destination(egbase) == port) {
@@ -339,10 +339,10 @@
return ships_on_way;
}
-uint32_t Fleet::count_ports() {
+uint32_t Fleet::count_ports() const {
return ports_.size();
}
-bool Fleet::get_act_pending() {
+bool Fleet::get_act_pending() const {
return act_pending_;
}
@@ -568,7 +568,7 @@
}
}
-bool Fleet::has_ports() {
+bool Fleet::has_ports() const {
return !ports_.empty();
}
@@ -863,7 +863,7 @@
}
}
-void Fleet::log_general_info(const EditorGameBase& egbase) {
+void Fleet::log_general_info(const EditorGameBase& egbase) const {
MapObject::log_general_info(egbase);
molog("%" PRIuS " ships and %" PRIuS " ports\n", ships_.size(), ports_.size());
=== modified file 'src/economy/fleet.h'
--- src/economy/fleet.h 2018-04-16 07:03:12 +
+++ src/economy/fleet.h 2018-09-05 07:39:19 +
@@ -92,17 +92,17 @@
void remove_ship(EditorGameBase& egbase, Ship* ship);
void add_port(EditorGameBase& egbase, PortDock* port);
void remove_port(EditorGameBase& egbase, PortDock* port);
- bool has_ports();
+ bool has_ports() const;
- void log_general_info(const EditorGameBase&) override;
+ void log_general_info(const EditorGameBase&) const override;
bool get_path(PortDock& start, PortDock& end, Path& path);
void add_neighbours(PortDock& pd, std::vector& neighbours);
- uint32_t count_ships();
- uint32_t count_ships_heading_here(EditorGameBase& egbase, PortDock* port);
- uint32_t count_ports();
- bool get_act_pending();
+ uint32_t count_ships() const;
+ uint32_t count_ships_heading_here(EditorGameBase& egbase, PortDock* port) const;
+ uint32_t count_ports() const;
+ bool get_act_pending() const;
protected:
void act(Game&, uint32_t data) override;
=== modified file 'src/economy/portdock.cc'
--- src/economy/portdock.cc 2018-04-16 07:03:12 +
+++ src/economy/portdock.cc 2018-09-05 07:39:19 +
@@ -384,10 +384,10 @@
/**
* Return the number of wares or workers of the given type that are waiting at the dock.
*/
-uint32_t PortDock::count_waiting(WareWorker waretype, DescriptionIndex wareindex) {
+uint32_t PortDock::count_waiting(WareWorker waretype, DescriptionIndex wareindex) const {
uint32_t count = 0;
- for (ShippingItem& shipping_item : waiting_) {
+ for (const ShippingItem& shipping_item : waiting_) {
WareInstance* ware;
Wo