omnizip 0.3.16 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4417d9e90649e837f75b25bcee26c0721283e360d015eaf0c4194fa2957be053
4
- data.tar.gz: 8c5fc8e793ea023d21abd9b044c3ddfb3786ee90225fe57fb322fa8cc60c5f4a
3
+ metadata.gz: 26bb587688afe9104a60ed3db30bd0b4d4a0ad909d1f02d0afaf3c8b67343119
4
+ data.tar.gz: 674f6bdf6fa36ec488ad06aa3f0a98ba792945fff3d244e9913ee06ff64402a6
5
5
  SHA512:
6
- metadata.gz: 2de569d977b1b47bc476efd9eb17e8f00c5b803e96451592964ee0f43bfa04caf52fd6462d02fbcaf9bd914b32436a210b1b935d24d6c1ad96a61acf119c7ca4
7
- data.tar.gz: c070c98a67fef377cf8710f89ed922bb0a6ff5cf8edd0ac7307113f4973d07a85c5eb8dfce48210f7d570687d361f68cc61f947d4dc739588f9aee1662126269
6
+ metadata.gz: ed59928f26cec56627b12304d9cf55d3ed04a7ee07f0a3bf2ef6f71b44a0e21d76d4246746db8f5dd0751139f68208a5a5a53c81ce9959f4433f883d3648adfc
7
+ data.tar.gz: 311d21ef3715257f1db58f9c1238200d04dce604022337fa53adf7a2c95d1a2d1272ba75bbcae55aaaf5d5b97a16ef954e7ab1b423e9f6875abb1f1036653a6b
@@ -177,7 +177,12 @@ module Omnizip
177
177
  limit = block_end - mm
178
178
 
179
179
  while ip < limit
180
- match = find_best_match(src, ip, ms, mm, limit)
180
+ match = if lazy.zero?
181
+ find_greedy_match(src, ip, ms, mm, limit, anchor,
182
+ seq_store.rep_offsets[0])
183
+ else
184
+ find_best_match(src, ip, ms, mm, limit)
185
+ end
181
186
  if match
182
187
  dist, len = match
183
188
  defer = false
@@ -198,6 +203,7 @@ module Omnizip
198
203
  next
199
204
  end
200
205
 
206
+ ip = match[2] if match.length == 3
201
207
  seq_store.literals << src.byteslice(anchor, ip - anchor)
202
208
  seq_store.sequences <<
203
209
  RawSequence.new(ip - anchor, len, dist)
@@ -218,6 +224,55 @@ module Omnizip
218
224
  # rubocop:enable Metrics/AbcSize
219
225
  # rubocop:enable Metrics/MethodLength
220
226
 
227
+ # Greedy-path match search (port of the Rust
228
+ # compress_block_with_min_match): the rep0 fast-path first
229
+ # (cheapest offset to encode), then the hash table — both
230
+ # with backward extension into the pending literals. Returns
231
+ # [offset, length, start] or nil.
232
+ def find_greedy_match(src, ip, ms, min_match, limit, anchor, rep0)
233
+ m = rep0_match(src, ip, rep0, min_match, limit, anchor)
234
+ return m if m
235
+
236
+ dist, len = find_best_match(src, ip, ms, min_match, limit)
237
+ return nil unless dist
238
+
239
+ back = backward_extension(src, ip, anchor, ip - dist)
240
+ [dist, len + back, ip - back]
241
+ end
242
+
243
+ # Match at distance rep0 (the decoder's most recent offset)
244
+ # with forward and backward extension. [rep0, length, start]
245
+ # or nil.
246
+ #
247
+ # rubocop:disable-next Metrics/AbcSize
248
+ def rep0_match(src, ip, rep0, min_match, limit, anchor)
249
+ return nil if rep0 <= 0 || ip <= rep0
250
+ return nil if src.byteslice(ip, MIN_MATCH) !=
251
+ src.byteslice(ip - rep0, MIN_MATCH)
252
+
253
+ m_len = MIN_MATCH + count_match(
254
+ src, ip + MIN_MATCH, src, ip + MIN_MATCH - rep0,
255
+ [limit + MIN_MATCH_ECONOMICAL - ip - MIN_MATCH, 0].max
256
+ )
257
+ back = backward_extension(src, ip, anchor, ip - rep0)
258
+ m_len += back
259
+ return nil if m_len < min_match
260
+
261
+ [rep0, m_len, ip - back]
262
+ end
263
+
264
+ # Bytes before `ip` (and before the match candidate) that
265
+ # extend the match backward, bounded by the pending literal
266
+ # run so the previous sequence is never overlapped.
267
+ def backward_extension(src, ip, anchor, candidate)
268
+ back = 0
269
+ while ip > anchor + back && candidate > back &&
270
+ src.getbyte(ip - 1 - back) == src.getbyte(candidate - 1 - back)
271
+ back += 1
272
+ end
273
+ back
274
+ end
275
+
221
276
  # Find the best match at `ip` (single probe, or a chain walk
222
277
  # when enabled). Updates the hash table. Returns
223
278
  # [distance, length] or nil.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Omnizip
4
- VERSION = "0.3.16"
4
+ VERSION = "0.3.17"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnizip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-08-24 00:00:00.000000000 Z
11
+ date: 2026-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64