From: Jay Freeman (saurik) Date: Thu, 26 Nov 2015 10:17:14 +0000 (-0800) Subject: Maybe thread local storage is a performance issue. X-Git-Tag: v0.9.590~274 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/2c1d569a0ed9ddd14d3d1d73ee8be776e0889d35 Maybe thread local storage is a performance issue. --- diff --git a/Complete.cpp b/Complete.cpp index b378b60..75b80c0 100644 --- a/Complete.cpp +++ b/Complete.cpp @@ -26,10 +26,10 @@ #include "Replace.hpp" #include "String.hpp" -static CYExpression *ParseExpression(CYUTF8String code) { +static CYExpression *ParseExpression(CYPool &pool, CYUTF8String code) { std::stringstream stream; stream << '(' << code << ')'; - CYDriver driver(stream); + CYDriver driver(pool, stream); cy::parser parser(driver); if (parser.parse() != 0 || !driver.errors_.empty()) @@ -55,7 +55,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri CYLocalPool pool; std::istringstream stream(line); - CYDriver driver(stream); + CYDriver driver(pool, stream); driver.auto_ = true; @@ -99,7 +99,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri std::string begin(prefix.str()); - driver.program_ = $ CYProgram($ CYExpress($C3(ParseExpression( + driver.program_ = $ CYProgram($ CYExpress($C3(ParseExpression(pool, " function(object, prefix, word) {\n" " var names = [];\n" " var before = prefix.length;\n" @@ -122,7 +122,7 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri CYUTF8String json(run(pool, code)); // XXX: if this fails we should not try to parse it - CYExpression *result(ParseExpression(json)); + CYExpression *result(ParseExpression(pool, json)); if (result == NULL) return NULL; diff --git a/Console.cpp b/Console.cpp index f57ecea..f6ba47b 100644 --- a/Console.cpp +++ b/Console.cpp @@ -104,10 +104,10 @@ void Setup(CYDriver &driver) { driver.strict_ = true; } -void Setup(CYPool &pool, CYOutput &out, CYDriver &driver, CYOptions &options, bool lower) { +void Setup(CYOutput &out, CYDriver &driver, CYOptions &options, bool lower) { out.pretty_ = pretty_; if (lower) - driver.Replace(pool, options); + driver.Replace(options); } static CYUTF8String Run(CYPool &pool, int client, CYUTF8String code) { @@ -379,11 +379,12 @@ static void Console(CYOptions &options) { code = command_; else { std::istringstream stream(command_); - CYDriver driver(stream); - Setup(driver); CYPool pool; - bool failed(driver.Parse(pool)); + CYDriver driver(pool, stream); + Setup(driver); + + bool failed(driver.Parse()); if (failed || !driver.errors_.empty()) { for (CYDriver::Errors::const_iterator error(driver.errors_.begin()); error != driver.errors_.end(); ++error) { @@ -424,7 +425,7 @@ static void Console(CYOptions &options) { std::stringbuf str; CYOutput out(str, options); - Setup(pool, out, driver, options, lower); + Setup(out, driver, options, lower); out << *driver.program_; code = str.str(); } @@ -743,11 +744,11 @@ int Main(int argc, char * const argv[], char const * const envp[]) { _assert(!stream->fail()); } - CYDriver driver(*stream, script); + CYPool pool; + CYDriver driver(pool, *stream, script); Setup(driver); - CYPool pool; - bool failed(driver.Parse(pool)); + bool failed(driver.Parse()); if (failed || !driver.errors_.empty()) { for (CYDriver::Errors::const_iterator i(driver.errors_.begin()); i != driver.errors_.end(); ++i) @@ -755,7 +756,7 @@ int Main(int argc, char * const argv[], char const * const envp[]) { } else if (driver.program_ != NULL) { std::stringbuf str; CYOutput out(str, options); - Setup(pool, out, driver, options, true); + Setup(out, driver, options, true); out << *driver.program_; std::string code(str.str()); if (compile) diff --git a/Cycript.l.in b/Cycript.l.in index 8c183a4..064d43a 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -49,8 +49,9 @@ typedef cy::parser::token tk; return token; \ } while (false) -#define A new($pool) -#define Y $pool.strmemdup(yytext, yyleng) +#define P yyextra->pool_ +#define A new(P) +#define Y P.strmemdup(yytext, yyleng) #define I(type, Type, value, highlight) do { \ yylval->type ## _ = A CY ## Type; \ diff --git a/Cycript.yy.in b/Cycript.yy.in index d797aed..29e9438 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -28,7 +28,7 @@ #include "Driver.hpp" #include "Parser.hpp" #include "Stack.hpp" -#define CYNew new($pool) +#define CYNew new(driver.pool_) @begin ObjectiveC #include "ObjectiveC/Syntax.hpp" diff --git a/Driver.cpp b/Driver.cpp index e529cbc..5f3ffa1 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -22,7 +22,8 @@ #include "Cycript.tab.hh" #include "Driver.hpp" -CYDriver::CYDriver(std::istream &data, const std::string &filename) : +CYDriver::CYDriver(CYPool &pool, std::istream &data, const std::string &filename) : + pool_(pool), state_(CYClear), data_(data), debug_(0), @@ -43,8 +44,8 @@ CYDriver::~CYDriver() { ScannerDestroy(); } -bool CYDriver::Parse(CYPool &pool) { - CYLocal local(&pool); +bool CYDriver::Parse() { + CYLocal local(&pool_); cy::parser parser(*this); #ifdef YYDEBUG parser.set_debug_level(debug_); @@ -52,8 +53,8 @@ bool CYDriver::Parse(CYPool &pool) { return parser.parse() != 0; } -void CYDriver::Replace(CYPool &pool, CYOptions &options) { - CYLocal local(&pool); +void CYDriver::Replace(CYOptions &options) { + CYLocal local(&pool_); CYContext context(options); program_->Replace(context); } diff --git a/Driver.hpp b/Driver.hpp index cd39cfb..88956fb 100644 --- a/Driver.hpp +++ b/Driver.hpp @@ -39,6 +39,7 @@ enum CYState { class _visible CYDriver { public: + CYPool &pool_; void *scanner_; CYState state_; @@ -107,11 +108,11 @@ class _visible CYDriver { void ScannerDestroy(); public: - CYDriver(std::istream &data, const std::string &filename = ""); + CYDriver(CYPool &pool, std::istream &data, const std::string &filename = ""); ~CYDriver(); - bool Parse(CYPool &pool); - void Replace(CYPool &pool, CYOptions &options); + bool Parse(); + void Replace(CYOptions &options); Condition GetCondition(); void SetCondition(Condition condition); diff --git a/Highlight.cpp b/Highlight.cpp index 73814ec..3e8aa7b 100644 --- a/Highlight.cpp +++ b/Highlight.cpp @@ -56,15 +56,15 @@ struct CYColor { }; _visible void CYLexerHighlight(const char *data, size_t size, std::ostream &output, bool ignore) { + CYLocalPool pool; + CYStream stream(data, data + size); - CYDriver driver(stream); + CYDriver driver(pool, stream); driver.commented_ = true; size_t offset(0); CYPosition current; - CYLocalPool pool; - YYSTYPE value; CYLocation location; diff --git a/Library.cpp b/Library.cpp index b04f2ca..258ef61 100644 --- a/Library.cpp +++ b/Library.cpp @@ -219,7 +219,7 @@ double CYCastDouble(const char *value) { CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) { CYLocalPool local; - CYDriver driver(stream); + CYDriver driver(local, stream); cy::parser parser(driver); _assert(parser.parse() == 0);