to_string is more efficient now
This commit is contained in:
parent
8b78ff87c9
commit
843eb3a72f
24
ml.cpp
24
ml.cpp
|
|
@ -53,14 +53,6 @@
|
||||||
#define LIST_TYPE "list"
|
#define LIST_TYPE "list"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Convert an object to a string using a string stream conveniently
|
|
||||||
#if __linux
|
|
||||||
#define to_string(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x )).str()
|
|
||||||
#else
|
|
||||||
#define to_string(x) static_cast<std::ostringstream>((std::ostringstream() << std::dec << x )).str()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Is this character a valid lisp symbol character
|
// Is this character a valid lisp symbol character
|
||||||
bool is_symbol(char ch) {
|
bool is_symbol(char ch) {
|
||||||
return (isalpha(ch) || ispunct(ch)) && ch != '(' && ch != ')' && ch != '"' && ch != '\'';
|
return (isalpha(ch) || ispunct(ch)) && ch != '(' && ch != ')' && ch != '"' && ch != '\'';
|
||||||
|
|
@ -281,9 +273,9 @@ MlValue MlValue::cast_to_float() const {
|
||||||
MlValue MlValue::cast_to_string() const {
|
MlValue MlValue::cast_to_string() const {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case INT:
|
case INT:
|
||||||
return MlValue::string(to_string(stack_data.i));
|
return MlValue::string(std::to_string(stack_data.i));
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
return MlValue::string(to_string(stack_data.f));
|
return MlValue::string(std::to_string(stack_data.f));
|
||||||
case STRING:
|
case STRING:
|
||||||
return *this;
|
return *this;
|
||||||
default:
|
default:
|
||||||
|
|
@ -544,9 +536,9 @@ std::string MlValue::display() const {
|
||||||
case ATOM:
|
case ATOM:
|
||||||
return str;
|
return str;
|
||||||
case INT:
|
case INT:
|
||||||
return to_string(stack_data.i);
|
return std::to_string(stack_data.i);
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
return to_string(stack_data.f);
|
return std::to_string(stack_data.f);
|
||||||
case STRING:
|
case STRING:
|
||||||
return str;
|
return str;
|
||||||
case LAMBDA:
|
case LAMBDA:
|
||||||
|
|
@ -562,7 +554,7 @@ std::string MlValue::display() const {
|
||||||
}
|
}
|
||||||
return "(" + result + ")";
|
return "(" + result + ")";
|
||||||
case BUILTIN:
|
case BUILTIN:
|
||||||
return "<" + str + " at " + to_string(long(stack_data.b)) + ">";
|
return "<" + str + " at " + std::to_string(long(stack_data.b)) + ">";
|
||||||
case NIL:
|
case NIL:
|
||||||
return "nil";
|
return "nil";
|
||||||
default:
|
default:
|
||||||
|
|
@ -581,9 +573,9 @@ std::string MlValue::debug() const {
|
||||||
case ATOM:
|
case ATOM:
|
||||||
return str;
|
return str;
|
||||||
case INT:
|
case INT:
|
||||||
return to_string(stack_data.i);
|
return std::to_string(stack_data.i);
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
return to_string(stack_data.f);
|
return std::to_string(stack_data.f);
|
||||||
case STRING:
|
case STRING:
|
||||||
for (size_t i = 0; i < str.length(); i++) {
|
for (size_t i = 0; i < str.length(); i++) {
|
||||||
if (str[i] == '"') result += "\\\"";
|
if (str[i] == '"') result += "\\\"";
|
||||||
|
|
@ -603,7 +595,7 @@ std::string MlValue::debug() const {
|
||||||
}
|
}
|
||||||
return "(" + result + ")";
|
return "(" + result + ")";
|
||||||
case BUILTIN:
|
case BUILTIN:
|
||||||
return "<" + str + " at " + to_string(long(stack_data.b)) + ">";
|
return "<" + str + " at " + std::to_string(long(stack_data.b)) + ">";
|
||||||
case NIL:
|
case NIL:
|
||||||
return "nil";
|
return "nil";
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue