feat(资源管理): 加速资源首次加载
build.yaml / build (push) Successful in 51s

This commit is contained in:
xiaoqidun committed 2026-10-15 17:26:57 +08:00
1 parent 5dea48d54b
commit 59e3a7d36e
2 files changed
+32 -6

No files matched your search

+21 -1
View File
@@ -40,6 +40,26 @@ type editorXMLPatch struct {
data []byte
}
// editorXMLReader 在内存XML上直接读取字节,按块检查长词元的取消信号
type editorXMLReader struct {
*bytes.Reader
ctx context.Context
remaining uint16
}
// ReadByte 读取XML词元字节,每4096字节检查取消状态
// 返回: byte 当前字节, error 取消或读取错误
func (r *editorXMLReader) ReadByte() (byte, error) {
if r.remaining == 0 {
if err := r.ctx.Err(); err != nil {
return 0, err
}
r.remaining = 4096
}
r.remaining--
return r.Reader.ReadByte()
}
// editorXMLPrefix 跳过UTF-8字节序标记和XML空白,探测后保留首个内容字节
// 入参: input 带缓冲的输入流,读取错误及取消信号由底层传递
// 返回: bool 是否以XML标记起始, error 读取错误
@@ -86,7 +106,7 @@ func parseEditorXML(data []byte) (*editorXML, error) {
func parseEditorXMLContext(ctx context.Context, data []byte) (*editorXML, error) {
var input io.Reader = bytes.NewReader(data)
if ctx != nil {
input = imageInput{ReadCloser: io.NopCloser(input), context: ctx}
input = &editorXMLReader{Reader: bytes.NewReader(data), ctx: ctx}
}
d := xml.NewDecoder(input)
var root *editorXML