Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use builtin:: functions where available #132

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ListUtil.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,7 @@ CODE:
ST(0) = boolSV((SvPOK(sv) || SvPOKp(sv)) && (SvNIOK(sv) || SvNIOKp(sv)));
XSRETURN(1);

#if !PERL_VERSION_GE(5, 40, 0)
SV *
blessed(sv)
SV *sv
Expand Down Expand Up @@ -1820,6 +1821,8 @@ CODE:
ST(0) = boolSV(SvROK(sv) && SvWEAKREF(sv));
XSRETURN(1);

#endif /* !PERL_VERSION_GE(5, 40, 0) */

int
readonly(sv)
SV *sv
Expand Down
13 changes: 13 additions & 0 deletions lib/Scalar/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ $VERSION =~ tr/_//d;
require List::Util; # List::Util loads the XS
List::Util->VERSION( $VERSION ); # Ensure we got the right XS version (RT#100863)

if( $] >= 5.040 ) {
# On Perl 5.40 and above, these builtins are stable, so we can use them
# instead of our own XS implementation

# Using this instead of a globref means we don't create an empty
# "builtins::" glob on older perls
no strict 'refs';
my $builtins = \%{"builtin::"};

*$_ = \&{ $builtins->{$_} } for (qw( blessed refaddr reftype weaken unweaken ));
*isweak = \&{ $builtins->{is_weak} }; # renamed
}

# populating @EXPORT_FAIL is done in the XS code
sub export_fail {
if (grep { /^isvstring$/ } @_ ) {
Expand Down
Loading