Skip to content

Optimize ora_regexp_count: drop wasteful text_to_cstring + strlen #1455

Closed

Description

@xuhuicai

Enhancement

The ora_regexp_count function had unnecessary full string copy and strlen scan when counting newline characters \n:

char *str = text_to_cstring(s);  // palloc + memcpy full copy
int   len = strlen(str);         // full scan

The raw byte pointer and length are already available via VARDATA_ANY(s) and VARSIZE_ANY_EXHDR(s), so the extra overhead is unnecessary.

Optimization

Replace text_to_cstring + strlen with VARDATA_ANY(s) + the existing src_text_len. Each call saves 1 palloc, 1 memcpy, and 1 full-string scan.

Behavioral difference

Only differs when the string contains embedded \0 (old code truncates at \0, new code uses the real length), which is extremely rare in text type.

Related PR: #1454

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions