This commit is contained in:
blueloveTH 2024-01-07 01:37:40 +08:00
parent 17cdeffbf5
commit f2ea8e28ec
2 changed files with 3 additions and 3 deletions

View File

@ -56,7 +56,7 @@ struct CodeEmitContext{
int for_loop_depth = 0;
std::map<void*, int> _co_consts_nonstring_dedup_map;
std::map<std::string, int> _co_consts_string_dedup_map;
std::map<std::string, int, std::less<>> _co_consts_string_dedup_map;
int get_loop() const;
CodeBlock* enter_block(CodeBlockType type);

View File

@ -89,14 +89,14 @@ namespace pkpy{
int CodeEmitContext::add_const(PyObject* v){
if(is_non_tagged_type(v, vm->tp_str)){
// string deduplication
std::string key = PK_OBJ_GET(Str, v).str();
std::string_view key = PK_OBJ_GET(Str, v).sv();
auto it = _co_consts_string_dedup_map.find(key);
if(it != _co_consts_string_dedup_map.end()){
return it->second;
}else{
co->consts.push_back(v);
int index = co->consts.size() - 1;
_co_consts_string_dedup_map[key] = index;
_co_consts_string_dedup_map[std::string(key)] = index;
return index;
}
}else{