Fixed cstr_buf for std::string with small string optimization
authorClifford Wolf <clifford@clifford.at>
Thu, 11 Jun 2015 11:39:49 +0000 (13:39 +0200)
committerClifford Wolf <clifford@clifford.at>
Thu, 11 Jun 2015 11:39:49 +0000 (13:39 +0200)
backends/blif/blif.cc
backends/btor/btor.cc
kernel/log.cc
kernel/rtlil.cc
kernel/yosys.h
passes/cmds/show.cc

index c257e496494a5bcd84b5723e0f1b223aa3279b30..af6f8726ade15f1bffb8774deb9720e15e039c84 100644 (file)
@@ -61,7 +61,7 @@ struct BlifDumper
        {
        }
 
-       std::vector<std::string> cstr_buf;
+       vector<shared_str> cstr_buf;
 
        const char *cstr(RTLIL::IdString id)
        {
index bcee505bea4be0592e240a8ab5ab85ab405c7632..079a82a2f9196657cd54c8a8864bbb8c0066367d 100644 (file)
@@ -155,7 +155,7 @@ struct BtorDumper
                 
        }
        
-       std::vector<std::string> cstr_buf;
+       vector<shared_str> cstr_buf;
 
        const char *cstr(const RTLIL::IdString id)
        {
index dbc94ce8c0a82dc319dc36022fdf617365fc35f7..91d85772356d90ca01e81d1e83d888998ba68985 100644 (file)
@@ -52,7 +52,7 @@ string log_last_error;
 
 vector<int> header_count;
 pool<RTLIL::IdString> log_id_cache;
-vector<string> string_buf;
+vector<shared_str> string_buf;
 int string_buf_index = -1;
 
 static struct timeval initial_tv = { 0, 0 };
index 373a3a5e6c98700b1c0c7469f64c56fa004a2e51..5deef8507246e5a0b4aeb5e6b26da361260ea275 100644 (file)
@@ -147,7 +147,7 @@ RTLIL::Const RTLIL::Const::from_string(std::string str)
 std::string RTLIL::Const::decode_string() const
 {
        std::string string;
-       std::vector <char> string_chars;
+       std::vector<char> string_chars;
        for (int i = 0; i < int (bits.size()); i += 8) {
                char ch = 0;
                for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
index db8161c5d2ebb826ca0660dc51474e0900f13812..14277ade832f5988c5b193131a2a8fd4ef9db826 100644 (file)
@@ -140,6 +140,17 @@ using std::vector;
 using std::string;
 using std::pair;
 
+// A primitive shared string implementation that does not
+// move its .c_str() when the object is copied or moved.
+struct shared_str {
+       std::shared_ptr<string> content;
+       shared_str() { }
+       shared_str(string s) { content = std::shared_ptr<string>(new string(s)); }
+       shared_str(const char *s) { content = std::shared_ptr<string>(new string(s)); }
+       const char *c_str() { return content->c_str(); }
+       const string &str() { return *content; }
+};
+
 using hashlib::mkhash;
 using hashlib::mkhash_init;
 using hashlib::mkhash_add;
index 81321665c3727f206b54ea2aec81f527805eb46c..0bcc768934f2262af3c63aacdcd45900a5ed438a 100644 (file)
@@ -41,7 +41,7 @@ struct ShowWorker
 {
        CellTypes ct;
 
-       std::vector<std::string> dot_escape_store;
+       vector<shared_str> dot_escape_store;
        std::map<RTLIL::IdString, int> dot_id2num_store;
        std::map<RTLIL::IdString, int> autonames;
        int single_idx_count;