ctx_parser 0.2.5 → 0.2.6

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: f5bf7a928b6287113d2db138fbd46ad11c22932b15ef99473caeedee6517dd07
4
- data.tar.gz: 5acef4c71f501bd931309afec028334831b86bafe67fd3e03411887bfdb401df
3
+ metadata.gz: 488dca1bfd052afe8a7719c6e5c89d4b2b5c86f189243c02b651438ce45a69c1
4
+ data.tar.gz: 33e7aa374cc8285c6dbb76ff4c9d87849116c3fa1a61ddb1ee720d108baed8ee
5
5
  SHA512:
6
- metadata.gz: 0ff61300ef0fc301eb315bf5d0e667534e996884ae6e83b2c08c0a630bf5f55da4a2faf2c7f97b23cba0520a71807c6393bb6a3fb8350b406632fd1930b1732d
7
- data.tar.gz: 180f90050ea5f2794d638eb9e64efc680b1ce0d07c786318eba5c22d2b48c6177c26156678777c4ae3e5e33fe5b3611c9cb7b8d2e1fd48f1e66be9c7c7020694
6
+ metadata.gz: 8459a636b16bdbe34e4446530714b1f686daa9bab80ca0cb713fdff9422066a388a7410dae7d083126c92415c8cb97f479a321da91d6113feb947cd03158bff6
7
+ data.tar.gz: ae3de9681c49c1d4be422c3b4b7c1fc47aeb0c152cb740370846fc3f80122435b184de6f2c977c3dac06d848c04a2c2d7191ad54d286214eee027c67d0b48abc
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@ Changes to the public contract are recorded here. Versions follow Semantic Versi
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.2.6 (2026-10-21)
8
+
9
+ - Build immutable hash snapshots without temporary field-pair arrays, retaining ordinary key equality, cycle rejection and deep-tree support.
10
+
11
+ - Add repository-specific AGENTS.md guidance for responsibilities, Ruby conventions, evidence boundaries and validation.
12
+ - Snapshot requested profile views before parser callbacks can mutate caller selections.
13
+ - Avoid redundant UTF-8 conversion and line-ending replacement for already normalized inputs while preserving mutable detached return values.
14
+
7
15
  ## 0.2.5 (2026-10-19)
8
16
 
9
17
  - Keep offline example facts and configuration benchmark inputs independent of Ruby's global input and output separators.
@@ -0,0 +1,19 @@
1
+ # 输入归一化验证(2026-10-21)
2
+
3
+ `Input.text` 的常见路径原先会对 UTF-8 输入再次执行 `encode(UTF_8)`,并在 LF 正文上执行无匹配的 `gsub`。现在跳过相同编码的转换,在没有 CR 时跳过替换;需要修改时只操作归一化过程拥有的副本。返回值仍可变且独立于调用方;原文、编码策略、逻辑 NUL 校验和转码前字节预算不变。
4
+
5
+ 在 macOS arm64、Ruby 4.0.6 上使用 `benchmark/input.rb`,对修改前的 `b8746d9` 与本次源码执行相同脚本。每轮重复归一化同一正文 30 次,共三轮;语义和对象所有权断言在计时外执行。下表是三轮中位数,属于重复输入的本地微基准,不代表设备采集、完整配置解析或网络吞吐。
6
+
7
+ | 正文 | 输入字节 | 修改前耗时 | 修改后耗时 | 修改前分配 | 修改后分配 |
8
+ | --- | ---: | ---: | ---: | ---: | ---: |
9
+ | UTF-8 / LF | 950000 | 67.354 ms | 0.866 ms | 120 | 30 |
10
+ | UTF-8 / CRLF | 1000000 | 177.798 ms | 162.056 ms | 150 | 150 |
11
+ | ISO-8859-1 / LF | 850000 | 169.909 ms | 90.748 ms | 150 | 60 |
12
+
13
+ 复测当前代码:
14
+
15
+ ```sh
16
+ bundle exec ruby -Ilib benchmark/input.rb
17
+ ```
18
+
19
+ 比较基线时,把目标提交的 `lib/ctx_parser/input.rb` 放入独立临时目录的 `ctx_parser/input.rb`,然后使用 `bundle exec ruby -I<临时目录> benchmark/input.rb`。脚本输出实际加载的 Input 来源,避免误测已安装版本。不要覆盖工作区文件来切换基线。
@@ -28,7 +28,9 @@ module CtxParser
28
28
  return value
29
29
  end
30
30
  copies[value] = if value.is_a?(Hash)
31
- value.to_h { |key, item| [ copy_value(key, copies, depth + 1), copy_value(item, copies, depth + 1) ] }.freeze
31
+ result = {}
32
+ value.each_pair { |key, item| result[copy_value(key, copies, depth + 1)] = copy_value(item, copies, depth + 1) }
33
+ result.freeze
32
34
  else
33
35
  value.map { |item| copy_value(item, copies, depth + 1) }.freeze
34
36
  end
@@ -69,7 +71,9 @@ module CtxParser
69
71
  copies[source] = if reusable?(source, copies, 0)
70
72
  source
71
73
  elsif source.is_a?(Hash)
72
- source.to_h { |key, item| [ snapshot(key, copies), snapshot(item, copies) ] }.freeze
74
+ result = {}
75
+ source.each_pair { |key, item| result[snapshot(key, copies)] = snapshot(item, copies) }
76
+ result.freeze
73
77
  else
74
78
  source.map { |item| snapshot(item, copies) }.freeze
75
79
  end
@@ -18,14 +18,18 @@ module CtxParser
18
18
  value.force_encoding(Encoding::UTF_8) if encoding == :utf8 || value.encoding == Encoding::BINARY
19
19
  raise EncodingError, "CLI output encoding is invalid" unless value.valid_encoding?
20
20
 
21
- value = value.encode(Encoding::UTF_8) if encoding == :transcode
21
+ value = value.encode(Encoding::UTF_8) if encoding == :transcode && value.encoding != Encoding::UTF_8
22
22
  # UTF-16/32 等编码不兼容 ASCII 字面量;仅在临时视图上检查逻辑字符。
23
23
  logical = value.encoding.ascii_compatible? ? value : value.encode(Encoding::UTF_8)
24
24
  raise ArgumentError, "CLI output contains a NUL byte" if !allow_nul && logical.include?("\0")
25
25
 
26
26
  normalized = case newlines
27
- when :lf then logical.gsub(/\r\n?/, "\n")
28
- when :delete_cr then logical.delete("\r")
27
+ when :lf
28
+ logical.gsub!(/\r\n?/, "\n") if logical.include?("\r")
29
+ logical
30
+ when :delete_cr
31
+ logical.delete!("\r")
32
+ logical
29
33
  else return value
30
34
  end
31
35
  normalized.encoding == value.encoding ? normalized : normalized.encode(value.encoding)
@@ -102,6 +102,8 @@ module CtxParser
102
102
  unless dimensions.is_a?(Array) && dimensions.any? && dimensions.uniq == dimensions
103
103
  raise ArgumentError, "Parser dimensions must be a nonempty unique array"
104
104
  end
105
+ # 扩展解析器可调用外部代码;结果投影始终使用入口处的请求。
106
+ dimensions = dimensions.dup.freeze
105
107
  query = select_command(dimensions, command)
106
108
 
107
109
  # 查询已覆盖全部请求维度,无需再次遍历第一个维度的完整命令列表。
@@ -2,5 +2,5 @@
2
2
 
3
3
  module CtxParser
4
4
  # 公开包版本,供 RubyGems 元数据和运行时调用方共用。
5
- VERSION = "0.2.5"
5
+ VERSION = "0.2.6"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ctx_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gatework contributors
@@ -48,6 +48,7 @@ files:
48
48
  - README-zh.md
49
49
  - README.md
50
50
  - docs/architecture-zh.md
51
+ - docs/input-performance.md
51
52
  - docs/release.md
52
53
  - examples/offline.rb
53
54
  - lib/ctx_parser.rb