From 914e2743f71419f25b2d35f7cbd9e09780235948 Mon Sep 17 00:00:00 2001 From: Andy Maleh Date: Mon, 1 Jul 2024 22:15:12 -0400 Subject: [PATCH] Optimize performance of `Glimmer::DataBinding::ObservableModel#add_observer` by removing `OpenStruct` constant check. --- CHANGELOG.md | 4 ++++ README.md | 4 ++-- VERSION | 2 +- glimmer.gemspec | 6 +++--- lib/glimmer/data_binding/observable_model.rb | 3 +-- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e23624618..6502dcce2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Related Change Logs: - [glimmer-dsl-swt/CHANGELOG.md](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/CHANGELOG.md) +### 2.7.9 + +- Optimize performance of `Glimmer::DataBinding::ObservableModel#add_observer` by removing `OpenStruct` constant check. + ### 2.7.8 - Allow passing `BindExpression` only 1 argument (e.g. presenter.todos) or 1 argument + 1 hash (e.g. presenter.todos, on_read: -> {}) diff --git a/README.md b/README.md index 641156d8d..e19c0a1d4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# [](https://rubygems.org/gems/glimmer) Glimmer 2.7.8 +# [](https://rubygems.org/gems/glimmer) Glimmer 2.7.9 ## DSL Framework for Ruby GUI and More [![Gem Version](https://badge.fury.io/rb/glimmer.svg)](http://badge.fury.io/rb/glimmer) [![rspec](https://github.com/AndyObtiva/glimmer/workflows/rspec/badge.svg)](https://github.com/AndyObtiva/glimmer/actions?query=workflow%3Arspec) @@ -268,7 +268,7 @@ end ### Setup Follow these steps to author a [Glimmer](https://rubygems.org/gems/glimmer) DSL: -- Add `gem 'glimmer', '~> 2.7.8'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.7.8` and add `require 'glimmer'` +- Add `gem 'glimmer', '~> 2.7.9'` to `Gemfile` and run `bundle` or run `gem install glimmer -v2.7.9` and add `require 'glimmer'` - Create `glimmer/dsl/[dsl_name]/dsl.rb`, which requires and adds all dynamic expressions for the [dsl_name] Glimmer DSL module as per the code shown in the previous section (or [Official DSLs](#official-dsls) as examples) - Create `glimmer/dsl/[dsl_name]/[expresion_name]_expresion.rb` for every [expresion_name] expression needed, whether dynamic or static diff --git a/VERSION b/VERSION index 6a81b4c83..3e651609d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.7.8 +2.7.9 diff --git a/glimmer.gemspec b/glimmer.gemspec index 73b99666f..9f78a54bd 100644 --- a/glimmer.gemspec +++ b/glimmer.gemspec @@ -2,16 +2,16 @@ # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- -# stub: glimmer 2.7.8 ruby lib +# stub: glimmer 2.7.9 ruby lib Gem::Specification.new do |s| s.name = "glimmer".freeze - s.version = "2.7.8" + s.version = "2.7.9" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= s.require_paths = ["lib".freeze] s.authors = ["AndyMaleh".freeze] - s.date = "2024-07-01" + s.date = "2024-07-02" s.description = "Glimmer is a Ruby DSL Framework for Ruby GUI and More, consisting of a DSL Engine and a Data-Binding Library (including Observer Design Pattern, Observable Model, Observable Array, and Observable Hash). Used in Glimmer DSL for SWT (JRuby Desktop Development GUI Framework), Glimmer DSL for Web (Ruby in the Browser Web Frontend Framework), Glimmer DSL for LibUI (Prerequisite-Free Ruby Desktop Development GUI Library and Winner of Fukuoka Ruby Award Competition 2022 Special Award), Glimmer DSL for Tk (Ruby Tk Desktop Development GUI Library), Glimmer DSL for GTK (Ruby-GNOME Desktop Development GUI Library), Glimmer DSL for FX (FOX Toolkit Ruby Desktop Development GUI Library), Glimmer DSL for WX (wxWidgets Ruby Desktop Development GUI Library), Glimmer DSL for Swing (JRuby Swing Desktop Development GUI Library), Glimmer DSL for JFX (JRuby JavaFX Desktop Development GUI Library), Glimmer DSL for XML (& HTML), and Glimmer DSL for CSS.".freeze s.email = "andy.am@gmail.com".freeze s.extra_rdoc_files = [ diff --git a/lib/glimmer/data_binding/observable_model.rb b/lib/glimmer/data_binding/observable_model.rb index 54ff1c9b9..51cc36287 100644 --- a/lib/glimmer/data_binding/observable_model.rb +++ b/lib/glimmer/data_binding/observable_model.rb @@ -56,8 +56,7 @@ def add_observer(observer, property_name, options = {}) property_observer_list(property_name) << observer # if property writer does not exist, add_property_writer_observers will ensure_array_object_observer only add_property_writer_observers(property_name, options) - open_struct_loaded = !!::OpenStruct rescue false - add_key_writer_observer(property_name, options) if is_a?(Struct) || (open_struct_loaded && is_a?(OpenStruct)) + add_key_writer_observer(property_name, options) unless (['Struct', 'OpenStruct'] & self.class.ancestors.map(&:to_s)).empty? observer end