fix: revert EncodeInt to return []byte for performance (by AI)
This commit is contained in:
parent
09af304a8c
commit
77e73281ad
@ -1,5 +1,12 @@
|
|||||||
# Changelog: @go/encoding
|
# 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
|
## [v1.3.2] - 2026-05-30
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -15,9 +15,9 @@ type IntEncoder struct {
|
|||||||
decodeMap [256]int
|
decodeMap [256]int
|
||||||
}
|
}
|
||||||
|
|
||||||
// EncodeInt 将整数转换为字符串
|
// EncodeInt 将整数转换为字节切片
|
||||||
func (enc *IntEncoder) EncodeInt(u uint64) string {
|
func (enc *IntEncoder) EncodeInt(u uint64) []byte {
|
||||||
return string(enc.AppendInt(nil, u))
|
return enc.AppendInt(nil, u)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AppendInt 将整数追加到已有字节切片中
|
// AppendInt 将整数追加到已有字节切片中
|
||||||
@ -130,8 +130,8 @@ func NewIntEncoder(digits string, radix uint8) (*IntEncoder, error) {
|
|||||||
var DefaultIntEncoder, _ = NewIntEncoder("9ukH1grX75TQS6LzpFAjIivsdZoO0mc8NBwnyYDhtMWEC2V3KaGxfJRPqe4lbU", 62)
|
var DefaultIntEncoder, _ = NewIntEncoder("9ukH1grX75TQS6LzpFAjIivsdZoO0mc8NBwnyYDhtMWEC2V3KaGxfJRPqe4lbU", 62)
|
||||||
var OrderedIntEncoder, _ = NewIntEncoder("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 62)
|
var OrderedIntEncoder, _ = NewIntEncoder("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 62)
|
||||||
|
|
||||||
// EncodeInt 使用默认编码器将整数转换为字符串
|
// EncodeInt 使用默认编码器将整数转换为字节切片
|
||||||
func EncodeInt(u uint64) string {
|
func EncodeInt(u uint64) []byte {
|
||||||
return DefaultIntEncoder.EncodeInt(u)
|
return DefaultIntEncoder.EncodeInt(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,9 @@ func init() {
|
|||||||
"HTMLUnescape": HTMLUnescape,
|
"HTMLUnescape": HTMLUnescape,
|
||||||
"UTF8Valid": UTF8Valid,
|
"UTF8Valid": UTF8Valid,
|
||||||
"SortJoin": SortJoin,
|
"SortJoin": SortJoin,
|
||||||
"EncodeInt": EncodeInt,
|
"EncodeInt": func(u uint64) string {
|
||||||
|
return string(EncodeInt(u))
|
||||||
|
},
|
||||||
"DecodeInt": DecodeInt,
|
"DecodeInt": DecodeInt,
|
||||||
"FillInt": FillInt,
|
"FillInt": FillInt,
|
||||||
"ExchangeInt": ExchangeInt,
|
"ExchangeInt": ExchangeInt,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user