From: Nicholas Clark Date: Tue, 8 Nov 2005 21:37:52 +0000 (+0000) Subject: Eliminate some unnecessary strlen()s X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=42d9b98d3f03094883cfc4bb765785a6d4396077;p=p5sagit%2Fp5-mst-13.2.git Eliminate some unnecessary strlen()s p4raw-id: //depot/perl@26050 --- diff --git a/doio.c b/doio.c index 76a632a..be67c6e 100644 --- a/doio.c +++ b/doio.c @@ -176,7 +176,7 @@ Perl_do_openn(pTHX_ GV *gv, register const char *oname, I32 len, int as_raw, IoTYPE(io) = PerlIO_intmode2str(rawmode, &mode[ix], &writing); - namesv = sv_2mortal(newSVpvn(oname,strlen(oname))); + namesv = sv_2mortal(newSVpv(oname,0)); num_svs = 1; svp = &namesv; type = Nullch; diff --git a/op.c b/op.c index 2eefa1d..2ca186c 100644 --- a/op.c +++ b/op.c @@ -5940,8 +5940,9 @@ Perl_ck_require(pTHX_ OP *o) for (s = SvPVX(sv); *s; s++) { if (*s == ':' && s[1] == ':') { + const STRLEN len = strlen(s+2)+1; *s = '/'; - Move(s+2, s+1, strlen(s+2)+1, char); + Move(s+2, s+1, len, char); SvCUR_set(sv, SvCUR(sv) - 1); } } diff --git a/perl.c b/perl.c index 3e7ccde..40c86c2 100644 --- a/perl.c +++ b/perl.c @@ -3818,6 +3818,7 @@ S_validate_suid(pTHX_ const char *validarg, const char *scriptname) if (PL_statbuf.st_mode & (S_ISUID|S_ISGID)) { I32 len; const char *linestr; + const char *s_end; #ifdef IAMSUID if (PL_fdscript < 0 || PL_suidscript != 1) @@ -3923,7 +3924,8 @@ S_validate_suid(pTHX_ const char *validarg, const char *scriptname) s = linestr; /* PSz 27 Feb 04 */ /* Sanity check on line length */ - if (strlen(s) < 1 || strlen(s) > 4000) + s_end = s + strlen(s); + if (s_end == s || (s_end - s) > 4000) Perl_croak(aTHX_ "Very long #! line"); /* Allow more than a single space after #! */ while (isSPACE(*s)) s++; @@ -3962,7 +3964,8 @@ S_validate_suid(pTHX_ const char *validarg, const char *scriptname) len = strlen(validarg); if (strEQ(validarg," PHOOEY ") || strnNE(s,validarg,len) || !isSPACE(s[len]) || - !(strlen(s) == len+1 || (strlen(s) == len+2 && isSPACE(s[len+1])))) + !((s_end - s) == len+1 + || ((s_end - s) == len+2 && isSPACE(s[len+1])))) Perl_croak(aTHX_ "Args must match #! line"); #ifndef IAMSUID diff --git a/perlio.c b/perlio.c index 8a23461..c7543d2 100644 --- a/perlio.c +++ b/perlio.c @@ -475,8 +475,8 @@ PerlIO_debug(const char *fmt, ...) /* Use fixed buffer as sv_catpvf etc. needs SVs */ char buffer[1024]; const STRLEN len = my_sprintf(buffer, "%.40s:%" IVdf " ", s ? s : "(none)", (IV) CopLINE(PL_curcop)); - vsprintf(buffer+len, fmt, ap); - PerlLIO_write(PL_perlio_debug_fd, buffer, strlen(buffer)); + const STRLEN len2 = vsprintf(buffer+len, fmt, ap); + PerlLIO_write(PL_perlio_debug_fd, buffer, len + len2); #else const char *s = CopFILE(PL_curcop); STRLEN len; @@ -4785,7 +4785,7 @@ PerlIO * PerlIO_open(const char *path, const char *mode) { dTHX; - SV *name = sv_2mortal(newSVpvn(path, strlen(path))); + SV *name = sv_2mortal(newSVpv(path, 0)); return PerlIO_openn(aTHX_ Nullch, mode, -1, 0, 0, NULL, 1, &name); } @@ -4794,7 +4794,7 @@ PerlIO * PerlIO_reopen(const char *path, const char *mode, PerlIO *f) { dTHX; - SV *name = sv_2mortal(newSVpvn(path, strlen(path))); + SV *name = sv_2mortal(newSVpv(path,0)); return PerlIO_openn(aTHX_ Nullch, mode, -1, 0, 0, f, 1, &name); } diff --git a/sv.c b/sv.c index 3e74969..4b83f13 100644 --- a/sv.c +++ b/sv.c @@ -8720,7 +8720,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV { q++; /* skip past the rest of the %vd format */ eptr = (const char *) vecstr; - elen = strlen(eptr); + elen = veclen; vectorize=FALSE; goto string; } diff --git a/toke.c b/toke.c index 0ec4e9f..cb13580 100644 --- a/toke.c +++ b/toke.c @@ -681,7 +681,8 @@ S_incline(pTHX_ char *s) if (t - s > 0) { #ifndef USE_ITHREADS const char * const cf = CopFILE(PL_curcop); - if (cf && strlen(cf) > 7 && strnEQ(cf, "(eval ", 6)) { + STRLEN tmplen = cf ? strlen(cf) : 0; + if (tmplen > 7 && strnEQ(cf, "(eval ", 6)) { /* must copy *{"::_<(eval N)[oldfilename:L]"} * to *{"::_