Strict `Text` wrapper unnecessarily decodes to `Char` for `text-2.*`

未关闭
#280 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
重构
描述清晰度
基本清楚
活跃度
停滞
技术栈
haskell
领域
compilers

调研方向

从 data/AlexWrappers.hs 的第 88-90 行和第 98-105 行开始,然后跟踪 alexInputPrevChar 以及 strict Text wrapper 的输入处理。保留 wrapper 的行为,同时移除不必要的 Text-to-Char 解码,包括 issue 中描述的向后字符边界处理。

由索引模型根据 Issue 内容生成。

描述

Looking at the code:

https://github.com/haskell/alex/blob/e65958c688ba04f8b14c888d7b55f16532510f51/data/AlexWrappers.hs#L88-L90

This can be replaced by:

type AlexInput = (Int,            -- current offset
                  Data.Text.Text) -- input string

https://github.com/haskell/alex/blob/e65958c688ba04f8b14c888d7b55f16532510f51/data/AlexWrappers.hs#L98-L105

This can be replaced by:

alexGetByte :: AlexInput -> Maybe (Byte,AlexInput)
alexGetByte (cur, input) = case input of
  Text arr off len
    | cur < len = Just (unsafeIndex arr (off + curr) (cur + 1, input))
    | otherwise = Nothing

The only thing "complicated" is alexInputPrevChar, basically you go back from cur one byte at a time until you have seen two character boundaries and then do a character decode at that position.

主要语言
Haskell
星标
323
派生
87
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

haskell/alex 的其他 Issue

查看 haskell/alex 的全部 Issue

相似的 Issue

更多 Haskell Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。