Skip to content

Conversation

@aaronskiba
Copy link

@aaronskiba aaronskiba commented Jul 30, 2025

If tmp_locale&.to_sym == self.locale, then temporarily reassigning self.locale is redundant. This small optimisation allows for early return when the locale is already set correctly.

@aaronskiba aaronskiba marked this pull request as draft July 31, 2025 16:58
If `tmp_locale&.to_sym == self.locale`, then temporarily reassigning `self.locale` is redundant. This small optimisation allows for early return when the locale is already set correctly.
@aaronskiba aaronskiba force-pushed the optimize-with_locale branch from 1b5b697 to c64cf14 Compare August 4, 2025 00:18
@aaronskiba
Copy link
Author

I recently cleaned up several instances of I18n.with_locale(I18n.locale) in a codebase I maintain and thought it might be worth applying the same idea here to avoid unnecessary temporary locale reassignment in the I18n source code.

That said, I realize the performance gain is likely negligible and may not justify the added conditionals. Feel free to close if it doesn't seem worthwhile. All the best.

@aaronskiba aaronskiba marked this pull request as ready for review August 4, 2025 19:54
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