perl - What's the difference between sv_catpv() and sv_catpvs()? -
perl - What's the difference between sv_catpv() and sv_catpvs()? -
according perlapi, sv_catpv() works follows:
concatenates nul-terminated string onto end of string in sv. if sv has utf-8 status set, bytes appended should valid utf-8. handles 'get' magic, not 'set' magic.
void sv_catpv(sv *const sv, const char* ptr)
most of xs tutorials i've found utilize sv_catpvs(), though, this:
like sv_catpvn, takes literal string instead of string/length pair.
void sv_catpvs(sv* sv, const char* s)
well, that's not helpful, let's @ sv_catpvn():
concatenates string onto end of string in sv. len indicates number of bytes copy. if sv has utf-8 status set, bytes appended should valid utf-8. handles 'get' magic, not 'set' magic.
void sv_catpvn(sv *dsv, const char *sstr, strlen len)
so, sv_catpvn same thing sv_catpv except takes string length separate parameter, , sv_catpvs same sv_catpvn except takes literal string.
is there subtle difference between sv_catpv , sv_catpvs i'm missing, or 2 ways same thing?
as per passages quoted, sv_catpvs takes string literal.
const char *str = "foo"; sv_catpvs(sv, "foo"); // ok sv_catpvs(sv, str); // error sv_catpv, on other hand, accepts look returns string.
sv_catpv(sv, "foo"); // ok sv_catpv(sv, str); // ok so why sv_catpvs exist @ all? because it's faster. reason sv_catpvs takes takes string literal it's macro expands
sv_catpvs(sv, "foo") into similar to
sv_catpvn_flags(sv, "foo", sizeof("foo")-1, sv_gmagic) which resolves to
sv_catpvn_flags(sv, "foo", 3, sv_gmagic) at compile-time. sv_catpv, on other hand, forced utilize slower strlen.
perl xs
Comments
Post a Comment