Skip to content

Commit

Permalink
Added small fixes in the parser and minimized allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanG077 committed Nov 15, 2018
1 parent 99493e2 commit 7439e4d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ std::vector<Box> Parser::getBoxes(std::istream& inputStream)
std::getline(inputStream, inputLine);

int16_t boxCount = 0;
static const auto max = std::numeric_limits<std::int16_t>::max() - 1;
static const auto max = 5000;
try {
auto tmp = std::stoi(inputLine);
if (tmp <= 0 || tmp > max) {
std::stringstream ss;
ss << "Amount of boxes is smaller then 1 or too large max allowed: " << max << ". Got: \"" << tmp << "\"";
ss << "Amount of boxes is smaller then 1 or too large, max allowed: " << max << ". Got: \"" << tmp << "\"";
throw ParserError(ss.str());
}
boxCount = static_cast<uint16_t>(tmp);
boxCount = static_cast<int16_t>(tmp);
} catch (const std::invalid_argument& e) {
std::stringstream ss;
ss << "Expected number to indicate amount of boxes to take from input. Got: \"" << inputLine << "\"";
Expand All @@ -33,7 +33,8 @@ std::vector<Box> Parser::getBoxes(std::istream& inputStream)
throw ParserError(ss.str(), e);
}

auto boxes = std::vector<Box>();
std::vector<Box> boxes;
boxes.reserve(boxCount);
for (std::size_t i = 0; i < boxCount; ++i) {
boxes.emplace_back(parseBoxSpecification(inputStream));
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/** Defines the project author */
#define BOXNESTING_AUTHOR "Ties Klappe & Rowan Goemans"
/** Defines the human-readable project version string (e.g. a.b.c.d-123+) */
#define BOXNESTING_VERSION "1.0.0-62277a7+"
#define BOXNESTING_VERSION "1.0.0-99493e2+"
/** Defines the project major version number */
#define BOXNESTING_VERSION_MAJOR 1
/** Defines the project major version number */
Expand Down

0 comments on commit 7439e4d

Please sign in to comment.