Pass arguments as lvalue-references.

This commit is contained in:
Kirill Kirilenko 2022-04-19 23:22:46 +03:00
parent 70d28978b7
commit 81e3686d3a
14 changed files with 41 additions and 35 deletions

View file

@ -66,7 +66,7 @@ public:
int dismantle(const Structure& target); int dismantle(const Structure& target);
int drop(std::string resourceType, std::optional<int> amount); int drop(const std::string& resourceType, std::optional<int> amount);
int generateSafeMode(const StructureController& target); int generateSafeMode(const StructureController& target);
@ -109,17 +109,17 @@ public:
int suicide(); int suicide();
int transfer(const Creep& target, int transfer(const Creep& target,
std::string resourceType, const std::string& resourceType,
std::optional<int> amount = std::nullopt); const std::optional<int>& amount = std::nullopt);
int transfer(const Structure& target, int transfer(const Structure& target,
std::string resourceType, const std::string& resourceType,
std::optional<int> amount = std::nullopt); const std::optional<int>& amount = std::nullopt);
int upgradeController(const StructureController& target); int upgradeController(const StructureController& target);
int withdraw(const RoomObject& target, int withdraw(const RoomObject& target,
std::string resourceType, const std::string& resourceType,
std::optional<int> amount = std::nullopt); const std::optional<int>& amount = std::nullopt);
}; };
} // namespace Screeps } // namespace Screeps

View file

@ -21,7 +21,7 @@ public:
void remove(); void remove();
int setColor(int color, std::optional<int> secondaryColor); int setColor(int color, const std::optional<int>& secondaryColor);
int setPosition(int x, int y); int setPosition(int x, int y);
int setPosition(const RoomPosition& pos); int setPosition(const RoomPosition& pos);

View file

@ -74,7 +74,7 @@ public:
void cpuHalt(); void cpuHalt();
int cpuSetShardLimits(std::map<std::string, int> limits); int cpuSetShardLimits(const std::map<std::string, int>& limits);
int cpuUnlock(); int cpuUnlock();

View file

@ -21,7 +21,7 @@ const static Value gGlobal = Value::global();
const static Value gObject = Value::global("Object"); const static Value gObject = Value::global("Object");
Value getGlobal(char const* name); Value getGlobal(char const* name);
Value getGlobal(std::string const& name); Value getGlobal(const std::string& name);
Value getConstant(const std::string& name); Value getConstant(const std::string& name);
bool isInstanceOf(const Value& val, const char* name); bool isInstanceOf(const Value& val, const char* name);

View file

@ -35,25 +35,25 @@ public:
// std::string serializePath(...) // std::string serializePath(...)
// ... deserializePath(const std::string path); // ... deserializePath(const std::string& path);
int createConstructionSite(int x, int createConstructionSite(int x,
int y, int y,
std::string structureType, const std::string& structureType,
std::optional<std::string> name = std::nullopt); const std::optional<std::string>& name = std::nullopt);
int createConstructionSite(const RoomPosition& pos, int createConstructionSite(const RoomPosition& pos,
std::string structureType, const std::string& structureType,
std::optional<std::string> name = std::nullopt); const std::optional<std::string>& name = std::nullopt);
int createFlag(int x, int createFlag(int x,
int y, int y,
std::optional<std::string> name = std::nullopt, const std::optional<std::string>& name = std::nullopt,
std::optional<std::string> color = std::nullopt, const std::optional<std::string>& color = std::nullopt,
std::optional<std::string> secondaryColor = std::nullopt); const std::optional<std::string>& secondaryColor = std::nullopt);
int createFlag(const RoomPosition& pos, int createFlag(const RoomPosition& pos,
std::optional<std::string> name = std::nullopt, const std::optional<std::string>& name = std::nullopt,
std::optional<std::string> color = std::nullopt, const std::optional<std::string>& color = std::nullopt,
std::optional<std::string> secondaryColor = std::nullopt); const std::optional<std::string>& secondaryColor = std::nullopt);
std::vector<std::unique_ptr<RoomObject>> std::vector<std::unique_ptr<RoomObject>>
find(int type, std::function<bool(const JS::Value&)> predicate = {}) const; find(int type, std::function<bool(const JS::Value&)> predicate = {}) const;
@ -87,7 +87,7 @@ public:
// ... lookAt(int x, int y); // ... lookAt(int x, int y);
// ... lookAt(const RoomPosition& target); // ... lookAt(const RoomPosition& target);
// ... lookAtArea(int top, int left, int bottom, int right, std::optional<bool> asArray = std::nullopt); // ... lookAtArea(int top, int left, int bottom, int right, const std::optional<bool>& asArray = std::nullopt);
// ... lookForAt(const std::string& type, int x, int y); // ... lookForAt(const std::string& type, int x, int y);
// ... lookForAt(const std::string& type, const RoomPosition& target); // ... lookForAt(const std::string& type, const RoomPosition& target);
@ -97,7 +97,7 @@ public:
// int left, // int left,
// int bottom, // int bottom,
// int right, // int right,
// std::optional<bool> asArray = std::nullopt); // const std::optional<bool>& asArray = std::nullopt);
}; };
} // namespace Screeps } // namespace Screeps

View file

@ -16,7 +16,7 @@ public:
Store store() const; Store store() const;
int transferEnergy(const StructureLink& target, std::optional<int> amount = std::nullopt); int transferEnergy(const StructureLink& target, const std::optional<int>& amount = std::nullopt);
}; };
} // namespace Screeps } // namespace Screeps

View file

@ -51,7 +51,7 @@ public:
int cancel(); int cancel();
int setDirections(std::vector<int> directions); int setDirections(const std::vector<int>& directions);
}; };
} // namespace Screeps } // namespace Screeps

View file

@ -20,7 +20,7 @@ public:
int send(const std::string& resourceType, int send(const std::string& resourceType,
int amount, int amount,
const std::string& destination, const std::string& destination,
std::optional<std::string> description = std::nullopt); const std::optional<std::string>& description = std::nullopt);
}; };
} // namespace Screeps } // namespace Screeps

View file

@ -125,7 +125,7 @@ int Creep::dismantle(const Structure& target)
return value().call<int>("dismantle", target.value()); return value().call<int>("dismantle", target.value());
} }
int Creep::drop(std::string resourceType, std::optional<int> amount) int Creep::drop(const std::string& resourceType, std::optional<int> amount)
{ {
if (amount) if (amount)
return value().call<int>("drop", resourceType, *amount); return value().call<int>("drop", resourceType, *amount);
@ -247,7 +247,9 @@ int Creep::suicide()
return value().call<int>("suicide"); return value().call<int>("suicide");
} }
int Creep::transfer(const Creep& target, std::string resourceType, std::optional<int> amount) int Creep::transfer(const Creep& target,
const std::string& resourceType,
const std::optional<int>& amount)
{ {
if (amount) if (amount)
return value().call<int>("transfer", target.value(), resourceType, *amount); return value().call<int>("transfer", target.value(), resourceType, *amount);
@ -255,7 +257,9 @@ int Creep::transfer(const Creep& target, std::string resourceType, std::optional
return value().call<int>("transfer", target.value(), resourceType); return value().call<int>("transfer", target.value(), resourceType);
} }
int Creep::transfer(const Structure& target, std::string resourceType, std::optional<int> amount) int Creep::transfer(const Structure& target,
const std::string& resourceType,
const std::optional<int>& amount)
{ {
if (amount) if (amount)
return value().call<int>("transfer", target.value(), resourceType, *amount); return value().call<int>("transfer", target.value(), resourceType, *amount);
@ -268,7 +272,9 @@ int Creep::upgradeController(const StructureController& target)
return value().call<int>("upgradeController", target.value()); return value().call<int>("upgradeController", target.value());
} }
int Creep::withdraw(const RoomObject& target, std::string resourceType, std::optional<int> amount) int Creep::withdraw(const RoomObject& target,
const std::string& resourceType,
const std::optional<int>& amount)
{ {
if (amount) if (amount)
return value().call<int>("withdraw", target.value(), resourceType, *amount); return value().call<int>("withdraw", target.value(), resourceType, *amount);

View file

@ -39,7 +39,7 @@ void Flag::remove()
value().call<void>("remove"); value().call<void>("remove");
} }
int Flag::setColor(int color, std::optional<int> secondaryColor) int Flag::setColor(int color, const std::optional<int>& secondaryColor)
{ {
if (secondaryColor) if (secondaryColor)
return value().call<int>("setColor", color, *secondaryColor); return value().call<int>("setColor", color, *secondaryColor);

View file

@ -9,7 +9,7 @@ Value getGlobal(char const* name)
return Value::global(name); return Value::global(name);
} }
Value getGlobal(std::string const& name) Value getGlobal(const std::string& name)
{ {
return Value::global(name.c_str()); return Value::global(name.c_str());
} }

View file

@ -18,7 +18,7 @@ Store StructureLink::store() const
return Store(value()["store"]); return Store(value()["store"]);
} }
int StructureLink::transferEnergy(const StructureLink& target, std::optional<int> amount) int StructureLink::transferEnergy(const StructureLink& target, const std::optional<int>& amount)
{ {
if (amount) if (amount)
return value().call<int>("transferEnergy", target.value(), *amount); return value().call<int>("transferEnergy", target.value(), *amount);

View file

@ -99,7 +99,7 @@ int StructureSpawn::Spawning::cancel()
return value().call<int>("cancel"); return value().call<int>("cancel");
} }
int StructureSpawn::Spawning::setDirections(std::vector<int> directions) int StructureSpawn::Spawning::setDirections(const std::vector<int>& directions)
{ {
return value().call<int>("setDirections", JS::vectorToJSArray(directions)); return value().call<int>("setDirections", JS::vectorToJSArray(directions));
} }

View file

@ -19,7 +19,7 @@ Store StructureTerminal::store() const
int StructureTerminal::send(const std::string& resourceType, int StructureTerminal::send(const std::string& resourceType,
int amount, int amount,
const std::string& destination, const std::string& destination,
std::optional<std::string> description) const std::optional<std::string>& description)
{ {
if (description) if (description)
return value().call<int>("send", resourceType, amount, destination, description); return value().call<int>("send", resourceType, amount, destination, description);