From e89240d6bff1c90f8b2d75513c230a0b4579a621 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Tue, 7 Oct 2025 09:59:27 -0600 Subject: [PATCH] perlapi: Consolidate the sv_eq and svstr_eq entries These functions do the same thing, differing in details. Consolidation makes perlapi more compact, and makes it easier for the reader to see the similarities and differences between the functions. Note that the cryptic sentence "It correctly handles the UTF8 flag" in the sv_streq entry has been removed. It turns out that meant that the code looks at the UTF8ness of each SV, except when 'use bytes' is in effect. --- sv.c | 62 ++++++++++++++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/sv.c b/sv.c index 5bea2ed6baf5..9557f01a55cb 100644 --- a/sv.c +++ b/sv.c @@ -8581,19 +8581,37 @@ S_assert_uft8_cache_coherent(pTHX_ const char *const func, STRLEN from_cache, /* =for apidoc sv_eq +=for apidoc_item sv_streq =for apidoc_item sv_eq_flags +=for apidoc_item sv_streq_flags -These each return a boolean indicating whether or not the strings in the two -SVs are equal. If S> is in effect, the comparison is -byte-by-byte; otherwise character-by-character. Each will coerce its args to -strings if necessary. +These each return a boolean indicating if the strings in the two SV arguments +are identical, coercing them to strings if necessary, basically behaving like +the Perl code S>. + +A NULL SV is treated as C. + +The comparison is character-by-character, based on the UTF8ness of each SV, +unless S> is in effect, in which case the comparison is +byte-by-byte. + +C and C always perform 'get' magic. +C and C perform 'get' magic only if C has +the C bit set. + +C and C do not check for overloading, always using regular +string comparison. -They differ only in that C always processes get magic, while -C processes get magic only when the C parameter has the -C bit set. +C always checks for, and if present, handles C overloading. If +not present, regular string comparison is used instead. -These functions do not handle operator overloading. For versions that do, -see instead C> or C>. +C normally checks for, and if present, handles C +overloading, but setting the C bit set in C causes it +to use regular string comparison. + +Otherwise, the functions behave identically. + +=for apidoc Amnh||SV_SKIP_OVERLOAD =cut */ @@ -8649,32 +8667,6 @@ Perl_sv_eq_flags(pTHX_ SV *sv1, SV *sv2, const U32 flags) return 0; } -/* -=for apidoc sv_streq -=for apidoc_item sv_streq_flags - -These each return a boolean indicating whether the strings in the two SVs are -identical. - -C is the more general form, having a C argument that -affects its behavior in two ways. It coerces its args to strings if necessary, -treating a C argument as C. It correctly handles the UTF8 flag. - -If C has the C bit set, 'get' magic will be handled. - -If flags does not have the C bit set, an attempt to use -C overloading will be made. If such overloading does not exist or the -flag is set, then regular string comparison will be used instead. - -C merely calls C with C set to just -C. This function basically behaves like the Perl code -S>. - -=for apidoc Amnh||SV_SKIP_OVERLOAD - -=cut -*/ - bool Perl_sv_streq_flags(pTHX_ SV *sv1, SV *sv2, const U32 flags) {