From 174b1425ef72c6a7eb6bc77588e5ca3a7a1c95da Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Fri, 7 Aug 2015 15:43:14 -0400 Subject: [PATCH] string_ref cont'd, considering token::msg Experimentation indicates that the sizeof(interned_string)=24 is so much larger than that of an empty sizeof(std::string)=8 that for mostly-empty slots it's a loss! A 1-byte std::string causes a 26-byte malloc, so the interned_string is probably good for nonempty strings. --- parse.cxx | 2 +- parse.h | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/parse.cxx b/parse.cxx index 94ea5eb0f..c092f80d3 100644 --- a/parse.cxx +++ b/parse.cxx @@ -1830,7 +1830,7 @@ skip: // ------------------------------------------------------------------------ void -token::make_junk (const string new_msg) +token::make_junk (const string& new_msg) { type = tok_junk; msg = new_msg; diff --git a/parse.h b/parse.h index 480288e02..573ea86b3 100644 --- a/parse.h +++ b/parse.h @@ -48,18 +48,19 @@ enum token_type struct token { source_loc location; - token_type type; interned_string content; - std::string msg; // for tok_junk - void make_junk (const std::string msg); + std::string msg; // for tok_junk, more efficient than interned_string if empty const token* chain; // macro invocation that produced this token + token_type type; + + void make_junk (const std::string& msg); friend class parser; friend class lexer; private: - token(): type(tok_junk), chain(0) {} + token(): chain(0), type(tok_junk) {} token(const token& other): - location(other.location), type(other.type), content(other.content), - msg(other.msg), chain(other.chain) {} + location(other.location), content(other.content), + msg(other.msg), chain(other.chain), type(other.type) {} }; -- 2.43.5