Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package rubygem-unicode-display_width for 
openSUSE:Factory checked in at 2023-10-10 21:00:05
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-unicode-display_width (Old)
 and      /work/SRC/openSUSE:Factory/.rubygem-unicode-display_width.new.28202 
(New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "rubygem-unicode-display_width"

Tue Oct 10 21:00:05 2023 rev:8 rq:1116490 version:2.4.2

Changes:
--------
--- 
/work/SRC/openSUSE:Factory/rubygem-unicode-display_width/rubygem-unicode-display_width.changes
      2022-10-12 18:26:58.077990530 +0200
+++ 
/work/SRC/openSUSE:Factory/.rubygem-unicode-display_width.new.28202/rubygem-unicode-display_width.changes
   2023-10-10 21:01:01.859672317 +0200
@@ -1,0 +2,21 @@
+Sat Sep  2 10:10:03 UTC 2023 - Mykola Krachkovsky <[email protected]>
+
+- updated to version 2.4.2
+
+  ## 2.4.2
+
+  More performance improvements:
+
+  - Optimize lookup of first 4096 codepoints
+  - Avoid overwrite lookup if no overwrites are set
+
+  ## 2.4.1
+
+  - Improve general performance!
+  - Further improve performance for ASCII strings
+
+  ## 2.4.0
+  - Improve performance for ASCII-only strings, by @fatkodima
+  - Require Ruby 2.4
+
+-------------------------------------------------------------------

Old:
----
  unicode-display_width-2.3.0.gem

New:
----
  unicode-display_width-2.4.2.gem

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ rubygem-unicode-display_width.spec ++++++
--- /var/tmp/diff_new_pack.fWGZAZ/_old  2023-10-10 21:01:03.115717864 +0200
+++ /var/tmp/diff_new_pack.fWGZAZ/_new  2023-10-10 21:01:03.119718009 +0200
@@ -1,7 +1,7 @@
 #
 # spec file for package rubygem-unicode-display_width
 #
-# Copyright (c) 2022 SUSE LLC
+# Copyright (c) 2023 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -24,7 +24,7 @@
 #
 
 Name:           rubygem-unicode-display_width
-Version:        2.3.0
+Version:        2.4.2
 Release:        0
 %define mod_name unicode-display_width
 %define mod_full_name %{mod_name}-%{version}

++++++ unicode-display_width-2.3.0.gem -> unicode-display_width-2.4.2.gem ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md
--- old/CHANGELOG.md    2022-09-14 09:59:01.000000000 +0200
+++ new/CHANGELOG.md    2023-01-04 12:17:21.000000000 +0100
@@ -1,5 +1,23 @@
 # CHANGELOG
 
+## 2.4.2
+
+More performance improvements:
+
+- Optimize lookup of first 4096 codepoints
+- Avoid overwrite lookup if no overwrites are set
+
+## 2.4.1
+
+- Improve general performance!
+- Further improve performance for ASCII strings
+
+*You should really upgrade - it's much faster now!*
+
+## 2.4.0
+- Improve performance for ASCII-only strings, by @fatkodima
+- Require Ruby 2.4
+
 ## 2.3.0
 
 - Unicode 15.0
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/MIT-LICENSE.txt new/MIT-LICENSE.txt
--- old/MIT-LICENSE.txt 2022-09-14 09:59:01.000000000 +0200
+++ new/MIT-LICENSE.txt 2023-01-04 12:17:21.000000000 +0100
@@ -1,6 +1,6 @@
 The MIT LICENSE
 
-Copyright (c) 2011, 2015-2022 Jan Lelis
+Copyright (c) 2011, 2015-2023 Jan Lelis
 
 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/README.md new/README.md
--- old/README.md       2022-09-14 09:59:01.000000000 +0200
+++ new/README.md       2023-01-04 12:17:21.000000000 +0100
@@ -1,12 +1,20 @@
 ## Unicode::DisplayWidth 
[![[version]](https://badge.fury.io/rb/unicode-display_width.svg)](https://badge.fury.io/rb/unicode-display_width)
 [<img 
src="https://github.com/janlelis/unicode-display_width/workflows/Test/badge.svg";
 
/>](https://github.com/janlelis/unicode-display_width/actions?query=workflow%3ATest)
 
-Determines the monospace display width of a string in Ruby. Implementation 
based on 
[EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) 
and other data, 100% in Ruby. It does not rely on the OS vendor (like 
[wcwidth()](https://github.com/janlelis/wcswidth-ruby)) to provide an 
up-to-date method for measuring string width.
+Determines the monospace display width of a string in Ruby. Useful for all 
kinds of terminal-based applications. Implementation based on 
[EastAsianWidth.txt](https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt) 
and other data, 100% in Ruby. It does not rely on the OS vendor (like 
[wcwidth()](https://github.com/janlelis/wcswidth-ruby)) to provide an 
up-to-date method for measuring string width.
 
 Unicode version: **15.0.0** (September 2022)
 
 Supported Rubies: **3.1**, **3.0**, **2.7**
 
-Old Rubies which might still work: **2.6**, **2.5**, **2.4**, **2.3**, 
**2.2**, **2.1**, **2.0**, **1.9**
+Old Rubies which might still work: **2.6**, **2.5**, **2.4**
+
+For even older Rubies, use version 2.3.0 of this gem: **2.3**, **2.2**, 
**2.1**, **2.0**, **1.9**
+
+## Version 2.4.2 — Performance Updates
+
+**If you use this gem, you should really upgrade to 2.4.2. It's often 100x 
faster, sometimes even 1000x and more!**
+
+This is possible because the gem now detects if you use very basic (and 
common) characters, like ASCII characters. Furthermore, the charachter width 
lookup code has been optimized, so even when full-width characters are 
involved, the gem is much faster now.
 
 ## Version 2.0 — Breaking Changes
 
@@ -39,7 +47,7 @@
 
-------|------------------------------|--------------------------------------------------
 X      | (user defined)               | Overwrites any other values
 -1     | `"\b"`                       | Backspace (total width never below 0)
-0      | `"\0"`, `"\x05"`, `"\a"`, `"\n"`, `"\v"`, `"\f"`, `"\r"`, `"\x0E"`, 
`"\x0F"` | [C0 control 
codes](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_.28ASCII_and_derivatives.29)
 that do not change horizontal width
+0      | `"\0"`, `"\x05"`, `"\a"`, `"\n"`, `"\v"`, `"\f"`, `"\r"`, `"\x0E"`, 
`"\x0F"` | [C0 control 
codes](https://en.wikipedia.org/wiki/C0_and_C1_control_codes#C0_.28ASCII_and_derivatives.29)
 which do not change horizontal width
 1      | `"\u{00AD}"`                 | SOFT HYPHEN
 2      | `"\u{2E3A}"`                 | TWO-EM DASH
 3      | `"\u{2E3B}"`                 | THREE-EM DASH
@@ -89,6 +97,9 @@
 Unicode::DisplayWidth.of("a\tb", 1, "\t".ord => 10)) # => tab counted as 10, 
so result is 12
 ```
 
+Please note that using overwrites disables some perfomance optimizations of 
this gem.
+
+
 #### Emoji Support
 
 Emoji width support is included, but in must be activated manually. It will 
adjust the string's size for modifier and zero-width joiner sequences. You also 
need to add the [unicode-emoji](https://github.com/janlelis/unicode-emoji) gem 
to your Gemfile:
@@ -154,7 +165,7 @@
 
 ## Copyright & Info
 
-- Copyright (c) 2011, 2015-2022 Jan Lelis, https://janlelis.com, released 
under the MIT
+- Copyright (c) 2011, 2015-2023 Jan Lelis, https://janlelis.com, released 
under the MIT
 license
 - Early versions based on runpaint's unicode-data interface: Copyright (c) 
2009 Run Paint Run Run
 - Unicode data: https://www.unicode.org/copyright.html#Exhibit1
Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/lib/unicode/display_width/constants.rb 
new/lib/unicode/display_width/constants.rb
--- old/lib/unicode/display_width/constants.rb  2022-09-14 09:59:01.000000000 
+0200
+++ new/lib/unicode/display_width/constants.rb  2023-01-04 12:17:21.000000000 
+0100
@@ -2,7 +2,7 @@
 
 module Unicode
   class DisplayWidth
-    VERSION = "2.3.0"
+    VERSION = "2.4.2"
     UNICODE_VERSION = "15.0.0"
     DATA_DIRECTORY = File.expand_path(File.dirname(__FILE__) + 
"/../../../data/")
     INDEX_FILENAME = DATA_DIRECTORY + "/display_width.marshal.gz"
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/lib/unicode/display_width/index.rb 
new/lib/unicode/display_width/index.rb
--- old/lib/unicode/display_width/index.rb      2022-09-14 09:59:01.000000000 
+0200
+++ new/lib/unicode/display_width/index.rb      2023-01-04 12:17:21.000000000 
+0100
@@ -10,5 +10,25 @@
       serialized_data.force_encoding Encoding::BINARY
       INDEX = Marshal.load(serialized_data)
     end
+
+    def self.decompress_index(index, level)
+      index.flat_map{ |value|
+        if level > 0
+          if value.instance_of?(Array)
+            value[15] ||= nil
+            decompress_index(value, level - 1)
+          else
+            decompress_index([value] * 16, level - 1)
+          end
+        else
+          if value.instance_of?(Array)
+            value[15] ||= nil
+            value
+          else
+            [value] * 16
+          end
+        end
+      }
+    end
   end
 end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/lib/unicode/display_width.rb 
new/lib/unicode/display_width.rb
--- old/lib/unicode/display_width.rb    2022-09-14 09:59:01.000000000 +0200
+++ new/lib/unicode/display_width.rb    2023-01-04 12:17:21.000000000 +0100
@@ -5,26 +5,84 @@
 
 module Unicode
   class DisplayWidth
-    DEPTHS = [0x10000, 0x1000, 0x100, 0x10].freeze
+    INITIAL_DEPTH = 0x10000
+    ASCII_NON_ZERO_REGEX = /[\0\x05\a\b\n\v\f\r\x0E\x0F]/
+    FIRST_4096 = decompress_index(INDEX[0][0], 1)
 
     def self.of(string, ambiguous = 1, overwrite = {}, options = {})
-      res = string.codepoints.inject(0){ |total_width, codepoint|
-        index_or_value = INDEX
-        codepoint_depth_offset = codepoint
-        DEPTHS.each{ |depth|
-          index_or_value         = index_or_value[codepoint_depth_offset / 
depth]
-          codepoint_depth_offset = codepoint_depth_offset % depth
-          break unless index_or_value.is_a? Array
-        }
-        width = index_or_value.is_a?(Array) ? 
index_or_value[codepoint_depth_offset] : index_or_value
-        width = ambiguous if width == :A
-        total_width + (overwrite[codepoint] || width || 1)
+      if overwrite.empty?
+        # Optimization for ASCII-only strings without certain control symbols
+        if string.ascii_only?
+          if string.match?(ASCII_NON_ZERO_REGEX)
+            res = string.gsub(ASCII_NON_ZERO_REGEX, "").size - 
string.count("\b")
+            res < 0 ? 0 : res
+          else
+            string.size
+          end
+        else
+          width_no_overwrite(string, ambiguous, options)
+        end
+      else
+        width_all_features(string, ambiguous, overwrite, options)
+      end
+    end
+
+    def self.width_no_overwrite(string, ambiguous, options = {})
+      # Sum of all chars widths
+      res = string.codepoints.sum{ |codepoint|
+        if codepoint > 15 && codepoint < 161 # very common
+          next 1
+        elsif codepoint < 0x1001
+          width = FIRST_4096[codepoint]
+        else
+          width = INDEX
+          depth = INITIAL_DEPTH
+          while (width = width[codepoint / depth]).instance_of? Array
+            codepoint %= depth
+            depth /= 16
+          end
+        end
+
+        width == :A ? ambiguous : (width || 1)
       }
 
+      # Substract emoji error
+      res -= emoji_extra_width_of(string, ambiguous) if options[:emoji]
+
+      # Return result + prevent negative lengths
+      res < 0 ? 0 : res
+    end
+
+    # Same as .width_no_overwrite - but with applying overwrites for each char
+    def self.width_all_features(string, ambiguous, overwrite, options)
+      # Sum of all chars widths
+      res = string.codepoints.sum{ |codepoint|
+        next overwrite[codepoint] if overwrite[codepoint]
+
+        if codepoint > 15 && codepoint < 161 # very common
+          next 1
+        elsif codepoint < 0x1001
+          width = FIRST_4096[codepoint]
+        else
+          width = INDEX
+          depth = INITIAL_DEPTH
+          while (width = width[codepoint / depth]).instance_of? Array
+            codepoint %= depth
+            depth /= 16
+          end
+        end
+
+        width == :A ? ambiguous : (width || 1)
+      }
+
+      # Substract emoji error
       res -= emoji_extra_width_of(string, ambiguous, overwrite) if 
options[:emoji]
+
+      # Return result + prevent negative lengths
       res < 0 ? 0 : res
     end
 
+
     def self.emoji_extra_width_of(string, ambiguous = 1, overwrite = {}, _ = 
{})
       require "unicode/emoji"
 
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/metadata new/metadata
--- old/metadata        2022-09-14 09:59:01.000000000 +0200
+++ new/metadata        2023-01-04 12:17:21.000000000 +0100
@@ -1,14 +1,14 @@
 --- !ruby/object:Gem::Specification
 name: unicode-display_width
 version: !ruby/object:Gem::Version
-  version: 2.3.0
+  version: 2.4.2
 platform: ruby
 authors:
 - Jan Lelis
 autorequire: 
 bindir: bin
 cert_chain: []
-date: 2022-09-14 00:00:00.000000000 Z
+date: 2023-01-04 00:00:00.000000000 Z
 dependencies:
 - !ruby/object:Gem::Dependency
   name: rspec
@@ -62,7 +62,7 @@
 licenses:
 - MIT
 metadata:
-  changelog_uri: 
https://github.com/janlelis/unicode-display_width/blob/master/CHANGELOG.md
+  changelog_uri: 
https://github.com/janlelis/unicode-display_width/blob/main/CHANGELOG.md
   source_code_uri: https://github.com/janlelis/unicode-display_width
   bug_tracker_uri: https://github.com/janlelis/unicode-display_width/issues
   rubygems_mfa_required: 'true'
@@ -74,14 +74,14 @@
   requirements:
   - - ">="
     - !ruby/object:Gem::Version
-      version: 1.9.3
+      version: 2.4.0
 required_rubygems_version: !ruby/object:Gem::Requirement
   requirements:
   - - ">="
     - !ruby/object:Gem::Version
       version: '0'
 requirements: []
-rubygems_version: 3.3.7
+rubygems_version: 3.4.1
 signing_key: 
 specification_version: 4
 summary: Determines the monospace display width of a string in Ruby.

Reply via email to