### ltlast: use the return of insert() to avoid a double lookup

```* src/ltlast/atomic_prop.cc, src/ltlast/automatop.cc,
src/ltlast/binop.cc, src/ltlast/bunop.cc,
src/ltlast/multop.cc, src/ltlast/unop.cc: Do not look for a key
and then insert the (key,value) on failure.  Simply insert
(key,0), and replace 0 by value on failure.  This replaces two map
lookups by one.```
parent 2776de87
 ... ... @@ -102,13 +102,13 @@ namespace spot atomic_prop::instance(const std::string& name, environment& env) { pair p(name, &env); // FIXME: Use lower_bound, or a hash_map. map::iterator i = instances.find(p); const atomic_prop* ap; if (i != instances.end()) ap = i->second; std::pair ires = instances.insert(map::value_type(p, 0)); if (!ires.second) ap = ires.first->second; else ap = instances[p] = new atomic_prop(name, env); ap = ires.first->second = new atomic_prop(name, env); ap->clone(); return ap; } ... ...
 ... ... @@ -95,19 +95,20 @@ namespace spot { assert(nfa != 0); triplet p(std::make_pair(nfa, negated), v); map::iterator i = instances.find(p); const automatop* res; if (i != instances.end()) std::pair ires = instances.insert(map::value_type(p, 0)); if (!ires.second) { // The instance already exists. for (vec::iterator vi = v->begin(); vi != v->end(); ++vi) (*vi)->destroy(); delete v; res = i->second; res = ires.first->second; } else { res = instances[p] = new automatop(nfa, v, negated); res = ires.first->second = new automatop(nfa, v, negated); } res->clone(); return res; ... ...
 ... ... @@ -525,19 +525,20 @@ namespace spot pairf pf(first, second); pair p(op, pf); // FIXME: Use lower_bound or hash_map. map::iterator i = instances.find(p); const binop* res; if (i != instances.end()) std::pair ires = instances.insert(map::value_type(p, 0)); if (!ires.second) { // This instance already exists. first->destroy(); second->destroy(); res = i->second; res = ires.first->second; } else { res = instances[p] = new binop(op, first, second); res = ires.first->second = new binop(op, first, second); } res->clone(); return res; ... ...
 ... ... @@ -262,14 +262,20 @@ namespace spot } pair p(pairo(op, child), pairu(min, max)); map::iterator i = instances.find(p); if (i != instances.end()) const formula* res; std::pair ires = instances.insert(map::value_type(p, 0)); if (!ires.second) { // This instance already exists. child->destroy(); return i->second->clone(); res = ires.first->second; } else { res = ires.first->second = new bunop(op, child, min, max); } const bunop* res = instances[p] = new bunop(op, child, min, max); res->clone(); return res; } ... ...
 ... ... @@ -588,21 +588,22 @@ namespace spot pair p(op, v); const multop* res; // FIXME: Use lower_bound or hash_map. map::iterator i = instances.find(p); if (i != instances.end()) // Insert the key p with the dummy value 0 just // to check if p already exists. std::pair ires = instances.insert(map::value_type(p, 0)); if (!ires.second) { // The instance already exists. // The instance did already exists. Free v. for (vec::iterator vi = v->begin(); vi != v->end(); ++vi) (*vi)->destroy(); delete v; res = i->second; res = ires.first->second; } else { // This is the first instance of this formula. // Record the instance in the map, res = instances[p] = new multop(op, v); // The instance did not already exist. res = ires.first->second = new multop(op, v); } res->clone(); return res; ... ...
 ... ... @@ -314,16 +314,18 @@ namespace spot const unop* res; pair p(op, child); map::iterator i = instances.find(p); if (i != instances.end()) std::pair ires = instances.insert(map::value_type(p, 0)); if (!ires.second) { // This instance already exists. child->destroy(); res = i->second; res = ires.first->second; } else { res = instances[p] = new unop(op, child); res = ires.first->second = new unop(op, child); } res->clone(); return res; ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
{"ft_lang_label":"__label__en","ft_lang_prob":0.52607095,"math_prob":0.96527594,"size":426,"snap":"2022-40-2023-06","text_gpt3_token_len":128,"char_repetition_ratio":0.21327014,"word_repetition_ratio":0.0,"special_character_ratio":0.24647887,"punctuation_ratio":0.19587629,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9762062,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-03T04:57:47Z\",\"WARC-Record-ID\":\"<urn:uuid:0f186b1f-f9b6-4dbc-bd0d-49e9c052bcc6>\",\"Content-Length\":\"346812\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a5d2f6e2-fa7b-43f1-a40c-51d61c8be086>\",\"WARC-Concurrent-To\":\"<urn:uuid:85b1f9b2-fb81-4fa7-af9b-6ba986eed2eb>\",\"WARC-IP-Address\":\"91.243.117.234\",\"WARC-Target-URI\":\"https://gitlab.lre.epita.fr/spot/spot/-/commit/13c41ee773fe59f7021be47b4d751491291f53d6\",\"WARC-Payload-Digest\":\"sha1:TWCS63BREXYXIJYAG6TE4S5AXO2QV537\",\"WARC-Block-Digest\":\"sha1:B27RUHMYOEY44NKE4H2MX4TAGGJXONK3\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764500042.8_warc_CC-MAIN-20230203024018-20230203054018-00675.warc.gz\"}"}