From f5dc669920ddd34276aa3c7c7000bdce9be26802 Mon Sep 17 00:00:00 2001 From: Fred-JulieDesk Date: Mon, 8 Feb 2016 14:07:01 +0100 Subject: [PATCH 1/2] Freezing the dot character to reduce memory usage from a considerable amount (5 MB min) --- lib/stringex/localization.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/stringex/localization.rb b/lib/stringex/localization.rb index 1629d2ed..139a2d2d 100644 --- a/lib/stringex/localization.rb +++ b/lib/stringex/localization.rb @@ -11,6 +11,9 @@ module Localization include DefaultConversions class << self + + DOT = ".".freeze + def backend @backend ||= i18n_present? ? Backend::I18n : Backend::Internal end @@ -36,7 +39,7 @@ def store_translations(locale, scope, data) end def translate(scope, key, options = {}) - return if key == "." # I18n doesn't support dots as translation keys so we don't either + return if key == DOT # I18n doesn't support dots as translation keys so we don't either locale = options[:locale] || self.locale From c797728c8d2e96bbeedd950f268a871f0013de6c Mon Sep 17 00:00:00 2001 From: Fred-JulieDesk Date: Fri, 17 Jun 2016 12:05:53 +0200 Subject: [PATCH 2/2] Optimizing Default conversions --- .gitignore | 1 + lib/stringex/localization/default_conversions.rb | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 37a28c0f..e281cf22 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ rdoc *.sqlite3 *.gem .ruby-* +.idea/ \ No newline at end of file diff --git a/lib/stringex/localization/default_conversions.rb b/lib/stringex/localization/default_conversions.rb index a60fb8f9..feb0702c 100644 --- a/lib/stringex/localization/default_conversions.rb +++ b/lib/stringex/localization/default_conversions.rb @@ -78,9 +78,11 @@ module DefaultConversions } class << self - %w{characters currencies html_entities transliterations vulgar_fractions}.each do |conversion_type| - define_method conversion_type do - const_get conversion_type.upcase + # %w{characters currencies html_entities transliterations vulgar_fractions} + + [['characters'.freeze, 'CHARACTERS'.freeze], ['currencies'.freeze, 'CURRENCIES'.freeze], ['html_entities'.freeze, 'HTML_ENTITIES'.freeze], ['transliterations'.freeze, 'TRANSLITERATIONS'.freeze], ['vulgar_fractions'.freeze, 'VULGAR_FRACTIONS'.freeze]].each do |conversion_type| + define_method conversion_type[0] do + const_get conversion_type[1] end end end