From 6bea42c1c09f3ad4111411ff3928ec07688f34ac Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sun, 31 Aug 2014 16:03:42 -0600 Subject: [PATCH] Speed up to_string performance by relying on C++ versions Addresses #134, fixing issues introduced by #132 --- include/chaiscript/dispatchkit/bootstrap.hpp | 6 +++--- include/chaiscript/language/chaiscript_common.hpp | 6 +----- include/chaiscript/language/chaiscript_prelude.chai | 5 ----- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index fbe2fd7..32aa939 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -472,8 +472,8 @@ namespace chaiscript operators::assign(m); operators::equal(m); - m->add(fun(&to_string), "internal_to_string"); - m->add(fun(&Bootstrap::bool_to_string), "internal_to_string"); + m->add(fun(&to_string), "to_string"); + m->add(fun(&Bootstrap::bool_to_string), "to_string"); m->add(fun(&unknown_assign), "="); m->add(fun(&throw_exception), "throw"); m->add(fun(&what), "what"); @@ -553,7 +553,7 @@ namespace chaiscript {fun(&AST_Node::filename), "filename"}, {fun(&AST_Node::start), "start"}, {fun(&AST_Node::end), "end"}, - {fun(&AST_Node::internal_to_string), "internal_to_string"}, + {fun(&AST_Node::to_string), "to_string"}, {fun(std::function (const chaiscript::AST_Node &t_node)>([](const chaiscript::AST_Node &t_node) { std::vector retval; std::transform(t_node.children.begin(), t_node.children.end(), diff --git a/include/chaiscript/language/chaiscript_common.hpp b/include/chaiscript/language/chaiscript_common.hpp index ec006d0..09987fa 100644 --- a/include/chaiscript/language/chaiscript_common.hpp +++ b/include/chaiscript/language/chaiscript_common.hpp @@ -430,17 +430,13 @@ namespace chaiscript oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") " << this->text << " : " << this->start.line << ", " << this->start.column << std::endl; - + for (size_t j = 0; j < this->children.size(); ++j) { oss << this->children[j]->to_string(t_prepend + " "); } return oss.str(); } - std::string internal_to_string() { - return to_string(); - } - Boxed_Value eval(chaiscript::detail::Dispatch_Engine &t_e) { try { diff --git a/include/chaiscript/language/chaiscript_prelude.chai b/include/chaiscript/language/chaiscript_prelude.chai index 426dc3b..b4c0bc4 100644 --- a/include/chaiscript/language/chaiscript_prelude.chai +++ b/include/chaiscript/language/chaiscript_prelude.chai @@ -56,11 +56,6 @@ def to_string(x) : call_exists(range, x) && !x.is_type("string"){ "[" + x.join(", ") + "]"; } -# Basic to_string function -def to_string(x) { - internal_to_string(x); -} - # Prints to console with no carriage return def puts(x) { print_string(x.to_string());