From 4c733301e6d13b6b13aef4549f262d05007ffc9f Mon Sep 17 00:00:00 2001 From: Clifford Wolf Date: Thu, 11 Jun 2015 13:39:49 +0200 Subject: [PATCH] Fixed cstr_buf for std::string with small string optimization --- backends/blif/blif.cc | 2 +- backends/btor/btor.cc | 2 +- kernel/log.cc | 2 +- kernel/rtlil.cc | 2 +- kernel/yosys.h | 11 +++++++++++ passes/cmds/show.cc | 2 +- 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/backends/blif/blif.cc b/backends/blif/blif.cc index c257e4964..af6f8726a 100644 --- a/backends/blif/blif.cc +++ b/backends/blif/blif.cc @@ -61,7 +61,7 @@ struct BlifDumper { } - std::vector cstr_buf; + vector cstr_buf; const char *cstr(RTLIL::IdString id) { diff --git a/backends/btor/btor.cc b/backends/btor/btor.cc index bcee505be..079a82a2f 100644 --- a/backends/btor/btor.cc +++ b/backends/btor/btor.cc @@ -155,7 +155,7 @@ struct BtorDumper } - std::vector cstr_buf; + vector cstr_buf; const char *cstr(const RTLIL::IdString id) { diff --git a/kernel/log.cc b/kernel/log.cc index dbc94ce8c..91d857723 100644 --- a/kernel/log.cc +++ b/kernel/log.cc @@ -52,7 +52,7 @@ string log_last_error; vector header_count; pool log_id_cache; -vector string_buf; +vector string_buf; int string_buf_index = -1; static struct timeval initial_tv = { 0, 0 }; diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 373a3a5e6..5deef8507 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -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 string_chars; + std::vector 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++) diff --git a/kernel/yosys.h b/kernel/yosys.h index db8161c5d..14277ade8 100644 --- a/kernel/yosys.h +++ b/kernel/yosys.h @@ -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 content; + shared_str() { } + shared_str(string s) { content = std::shared_ptr(new string(s)); } + shared_str(const char *s) { content = std::shared_ptr(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; diff --git a/passes/cmds/show.cc b/passes/cmds/show.cc index 81321665c..0bcc76893 100644 --- a/passes/cmds/show.cc +++ b/passes/cmds/show.cc @@ -41,7 +41,7 @@ struct ShowWorker { CellTypes ct; - std::vector dot_escape_store; + vector dot_escape_store; std::map dot_id2num_store; std::map autonames; int single_idx_count; -- 2.30.2