mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2026-01-29 17:38:16 +03:00
Refactor ss_toi() to not use stringstreams
Apart from the std::string, this function no longer uses the STL. ss_toi() is a simple function - it converts the input into an int, taking as many digits as possible until it reaches a non-digit character, at which point it stops. It's trivial to implement this without the STL. I could've used Int() here, but that would've required copying the string to a temporary buffer to insert a null-terminator (we can't just use a pointer-and-length data type either, the string functions don't operate like that - one disadvantage of C strings!). Instead, I decided to implement my own conversion to int here, because I don't think the way we humans write our Arabic numerals is going to change anytime soon. Also, the std::string input is now passed by const reference, instead of making a copy - cutting down on unnecessary memory operations.
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int ss_toi(std::string _s);
|
||||
int ss_toi(const std::string& str);
|
||||
|
||||
std::vector<std::string> split(const std::string &s, char delim, std::vector<std::string> &elems);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user