Skip to content

Fix redundant loop calling ConnectionsManager.setLangCode in LocaleController - #2032

Open
intelQong wants to merge 1 commit into
DrKLO:masterfrom
intelQong:fix-redundant-setlangcode-loop
Open

Fix redundant loop calling ConnectionsManager.setLangCode in LocaleController#2032
intelQong wants to merge 1 commit into
DrKLO:masterfrom
intelQong:fix-redundant-setlangcode-loop

Conversation

@intelQong

Copy link
Copy Markdown

Summary

In LocaleController.applyRemoteLanguage(), ConnectionsManager.setLangCode(localeInfo.getLangCode()) was being called inside a for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) loop.

However, ConnectionsManager.setLangCode() is a static method that already iterates over all accounts internally (0..UserConfig.MAX_ACCOUNT_COUNT) and invokes native_setLangCode(a, langCode) for each account:

public static void setLangCode(String langCode) {
    langCode = langCode.replace('_', '-').toLowerCase();
    for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
        native_setLangCode(a, langCode);
    }
}

Because of this outer loop in LocaleController, native_setLangCode was being called MAX_ACCOUNT_COUNT * MAX_ACCOUNT_COUNT times (16 calls when MAX_ACCOUNT_COUNT = 4), triggering redundant JNI string allocations and scheduling redundant native tasks to each account 4 times instead of once.

Changes

Remove the redundant outer for loop in LocaleController.applyRemoteLanguage(), aligning with the single invocation pattern used in LocaleController.applyLanguage().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant