SV* const sv = newSVsv(prog->substrs->data[i].substr);
prog->substrs->data[i].utf8_substr = sv;
sv_utf8_upgrade(sv);
- if (SvVALID(prog->substrs->data[i].substr))
- fbm_compile(sv, 0);
- if (SvTAIL(prog->substrs->data[i].substr))
- SvTAIL_on(sv);
+ if (SvVALID(prog->substrs->data[i].substr)) {
+ const U8 flags = BmFLAGS(prog->substrs->data[i].substr);
+ if (flags & FBMcf_TAIL) {
+ /* Trim the trailing \n that fbm_compile added last
+ time. */
+ SvCUR_set(sv, SvCUR(sv) - 1);
+ /* Whilst this makes the SV technically "invalid" (as its
+ buffer is no longer followed by "\0") when fbm_compile()
+ adds the "\n" back, a "\0" is restored. */
+ }
+ fbm_compile(sv, flags);
+ }
if (prog->substrs->data[i].substr == prog->check_substr)
prog->check_utf8 = sv;
}
&& !prog->substrs->data[i].substr) {
SV* sv = newSVsv(prog->substrs->data[i].utf8_substr);
if (sv_utf8_downgrade(sv, TRUE)) {
- if (SvVALID(prog->substrs->data[i].utf8_substr))
- fbm_compile(sv, 0);
- if (SvTAIL(prog->substrs->data[i].utf8_substr))
- SvTAIL_on(sv);
+ if (SvVALID(prog->substrs->data[i].utf8_substr)) {
+ const U8 flags
+ = BmFLAGS(prog->substrs->data[i].utf8_substr);
+ if (flags & FBMcf_TAIL) {
+ /* Trim the trailing \n that fbm_compile added last
+ time. */
+ SvCUR_set(sv, SvCUR(sv) - 1);
+ }
+ fbm_compile(sv, flags);
+ }
} else {
SvREFCNT_dec(sv);
sv = &PL_sv_undef;
= (unsigned char*)(SvPVX_mutable(sv) + len + PERL_FBM_TABLE_OFFSET);
s = table - 1 - PERL_FBM_TABLE_OFFSET; /* last char */
memset((void*)table, mlen, 256);
- BmFLAGS(sv) = (U8)flags;
i = 0;
sb = s - mlen + 1; /* first char (maybe) */
while (s >= sb) {
frequency = PL_freq[s[i]];
}
}
+ BmFLAGS(sv) = (U8)flags;
BmRARE(sv) = s[rarest];
BmPREVIOUS(sv) = rarest;
BmUSEFUL(sv) = 100; /* Initial value */