diff --git a/CHANGELOG.md b/CHANGELOG.md index 56a93bf..6221bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog: @go/encoding +## v1.5.2 (2026-06-08) +- **回滚与修复**: 修正了 `v1.5.1` 中架构设计的失误,将 Go 核心层的 `EncodeInt` 及 `IntEncoder.EncodeInt` 返回值从 `string` 恢复为 `[]byte`,彻底消除由于频繁强制转换导致的内存逃逸,恢复了高频并发场景下的零拷贝性能基准。 +- **JS 智能桥接**: 通过在 `js_export.go` 的注册阶段采用匿名闭包函数 `func(u uint64) string`,完美兼顾了底层的高效性和 JS 环境面向字符串开发的友好体验。 + +## v1.5.1 (2026-06-08) +- **JS 对齐**: 将所有注册到 `jsmod` 的导出方法名统一为 PascalCase,并将缩写名称(如 URL, HTML, UTF8)全大写,以消除 JS 与 Go 调用体感上的摩擦。合并了冗余的 `xxxToString` 方法。 + ## [v1.3.2] - 2026-05-30 ### Added diff --git a/int_encoder.go b/int_encoder.go index 8a5e2f0..22736fa 100644 --- a/int_encoder.go +++ b/int_encoder.go @@ -15,9 +15,9 @@ type IntEncoder struct { decodeMap [256]int } -// EncodeInt 将整数转换为字符串 -func (enc *IntEncoder) EncodeInt(u uint64) string { - return string(enc.AppendInt(nil, u)) +// EncodeInt 将整数转换为字节切片 +func (enc *IntEncoder) EncodeInt(u uint64) []byte { + return enc.AppendInt(nil, u) } // AppendInt 将整数追加到已有字节切片中 @@ -130,8 +130,8 @@ func NewIntEncoder(digits string, radix uint8) (*IntEncoder, error) { var DefaultIntEncoder, _ = NewIntEncoder("9ukH1grX75TQS6LzpFAjIivsdZoO0mc8NBwnyYDhtMWEC2V3KaGxfJRPqe4lbU", 62) var OrderedIntEncoder, _ = NewIntEncoder("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 62) -// EncodeInt 使用默认编码器将整数转换为字符串 -func EncodeInt(u uint64) string { +// EncodeInt 使用默认编码器将整数转换为字节切片 +func EncodeInt(u uint64) []byte { return DefaultIntEncoder.EncodeInt(u) } diff --git a/js_export.go b/js_export.go index 101c89c..1920fc7 100644 --- a/js_export.go +++ b/js_export.go @@ -18,7 +18,9 @@ func init() { "HTMLUnescape": HTMLUnescape, "UTF8Valid": UTF8Valid, "SortJoin": SortJoin, - "EncodeInt": EncodeInt, + "EncodeInt": func(u uint64) string { + return string(EncodeInt(u)) + }, "DecodeInt": DecodeInt, "FillInt": FillInt, "ExchangeInt": ExchangeInt,