@@ -440,7 +440,8 @@ class YueCompilerImpl {
440440 Scope* importingScope = nullptr ;
441441 std::string indent;
442442 std::string nl;
443- std::unordered_set<std::string> globals;
443+ std::unordered_set<std::string_view> globals;
444+ str_list globalList;
444445 };
445446 struct Scope {
446447 GlobalMode mode = GlobalMode::None;
@@ -1620,13 +1621,18 @@ class YueCompilerImpl {
16201621 return !_varArgs.empty () && _varArgs.top ().usedVar ? " end)(...)" s : " end)()" s;
16211622 }
16221623
1624+ void markGlobalImported (const std::string& name) {
1625+ if (_importedGlobal->globals .find (name) == _importedGlobal->globals .end () && !isSolidDefined (name)) {
1626+ const auto & global = _importedGlobal->globalList .emplace_back (name);
1627+ _importedGlobal->globals .insert (global);
1628+ _importedGlobal->importingScope ->vars ->insert_or_assign (name, VarType::LocalConst);
1629+ }
1630+ }
1631+
16231632 std::string globalVar (std::string_view var, ast_node* x, AccessType accessType) {
16241633 std::string str (var);
16251634 if (_importedGlobal) {
1626- if (_importedGlobal->globals .find (str) == _importedGlobal->globals .end () && !isSolidDefined (str)) {
1627- _importedGlobal->globals .insert (str);
1628- _importedGlobal->importingScope ->vars ->insert_or_assign (str, VarType::LocalConst);
1629- }
1635+ markGlobalImported (str);
16301636 } else if (_config.lintGlobalVariable ) {
16311637 if (!isLocal (str)) {
16321638 auto key = str + ' :' + std::to_string (x->m_begin .m_line ) + ' :' + std::to_string (x->m_begin .m_col );
@@ -4634,11 +4640,7 @@ class YueCompilerImpl {
46344640 transformVariable (static_cast <Variable_t*>(item), out);
46354641 if (accessType != AccessType::None) {
46364642 if (_importedGlobal) {
4637- const auto & str = out.back ();
4638- if (_importedGlobal->globals .find (str) == _importedGlobal->globals .end () && !isSolidDefined (str)) {
4639- _importedGlobal->globals .insert (str);
4640- _importedGlobal->importingScope ->vars ->insert_or_assign (str, VarType::LocalConst);
4641- }
4643+ markGlobalImported (out.back ());
46424644 } else if (_config.lintGlobalVariable && !isLocal (out.back ())) {
46434645 auto key = out.back () + ' :' + std::to_string (item->m_begin .m_line ) + ' :' + std::to_string (item->m_begin .m_col );
46444646 if (_globals.find (key) == _globals.end ()) {
@@ -5379,7 +5381,7 @@ class YueCompilerImpl {
53795381 }
53805382 if (auto importedGlobal = currentScope ().importedGlobal .get ()) {
53815383 str_list globalCodes;
5382- for (const auto & global : importedGlobal->globals ) {
5384+ for (const auto & global : importedGlobal->globalList ) {
53835385 globalCodes.emplace_back (importedGlobal->indent + " local " s + global + " = " s + global + importedGlobal->nl );
53845386 }
53855387 *importedGlobal->globalCodeLine = join (globalCodes);
@@ -9361,10 +9363,7 @@ class YueCompilerImpl {
93619363 out.push_back (name + " = " s + name);
93629364 }
93639365 if (_importedGlobal) {
9364- if (_importedGlobal->globals .find (name) == _importedGlobal->globals .end () && !isSolidDefined (name)) {
9365- _importedGlobal->globals .insert (name);
9366- _importedGlobal->importingScope ->vars ->insert_or_assign (name, VarType::LocalConst);
9367- }
9366+ markGlobalImported (name);
93689367 } else if (_config.lintGlobalVariable && !isLocal (name)) {
93699368 auto key = name + ' :' + std::to_string (pair->name ->m_begin .m_line ) + ' :' + std::to_string (pair->name ->m_begin .m_col );
93709369 if (_globals.find (key) == _globals.end ()) {
0 commit comments