Skip to content

Optimize ora_regexp_count: drop wasteful text_to_cstring + strlen #1455

Description

@xuhuicai

Enhancement

ora_regexp_count 函数中统计换行符 \n 数量的代码做了不必要的完整字符串拷贝和 strlen 扫描:

char *str = text_to_cstring(s);  // palloc + memcpy 完整拷贝
int   len = strlen(str);         // 从头扫描算长度

而原始字节指针和长度已经通过 VARDATA_ANY(s)VARSIZE_ANY_EXHDR(s) 得到,无需额外开销。

优化方案

VARDATA_ANY(s) + 已有 src_text_len 替换 text_to_cstring + strlen,每次调用省掉 1 次 palloc、1 次 memcpy、1 次全串扫描。

行为差异

仅当字符串中间嵌入 \0 时行为不同(旧代码在 \0 处截断,新代码使用真实长度),此场景在 text 类型中极为罕见。

关联 PR: #1454

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions