Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

A few little optimizations to some Str builtins. Found by looking at …

…profile of code from masak++; seems to shave a few percent off it.
  • Loading branch information...
commit f524138d1d29c99fa9963c7463afd34eda69c133 1 parent 99e7750
Jonathan Worthington authored April 15, 2012

Showing 1 changed file with 10 additions and 10 deletions. Show diff stats Hide diff stats

  1. 20  src/core/Str.pm
20  src/core/Str.pm
@@ -68,15 +68,15 @@ my class Str does Stringy {
68 68
     method substr(Str:D: $start, $length? is copy) {
69 69
         my str $sself  = nqp::unbox_s(self);
70 70
         my int $istart = nqp::unbox_i(
71  
-            $start.^does(Callable)
72  
-                ??  $start(nqp::p6box_i(nqp::chars($sself)))
  71
+            nqp::istype($start, Callable)
  72
+                ?? $start(nqp::p6box_i(nqp::chars($sself)))
73 73
                 !! $start.Int
74 74
             );
75 75
         my int $ichars = nqp::chars($sself);
76 76
         fail "Negative start argument ($start) to .substr" if $istart < 0;
77 77
         fail "Start of substr ($start) beyond end of string" if $istart > $ichars;
78 78
         $length = $length($ichars - $istart) if nqp::istype($length, Callable);
79  
-        my int $ilength = $length.defined ??  $length.Int !! $ichars - $istart;
  79
+        my int $ilength = $length.defined ?? $length.Int !! $ichars - $istart;
80 80
         fail "Negative length argument ($length) to .substr" if $ilength < 0;
81 81
 
82 82
         nqp::p6box_s(nqp::substr($sself, $istart, $ilength));
@@ -311,7 +311,7 @@ my class Str does Stringy {
311 311
     }
312 312
     multi method comb(Str:D: Regex $pat, $limit = $Inf, :$match) {
313 313
         my $x;
314  
-        $x = (1..$limit) unless $limit.^isa(Whatever) || $limit == $Inf;
  314
+        $x = (1..$limit) unless nqp::istype($limit, Whatever) || $limit == $Inf;
315 315
         $match
316 316
             ?? self.match(:g, :$x, $pat)
317 317
             !! self.match(:g, :$x, $pat).map: { .Str }
@@ -333,7 +333,7 @@ my class Str does Stringy {
333 333
           !! Match.new(orig => self, from => 0,    to => -3);
334 334
     }
335 335
     method match-list(Str:D: $pat, :$g, :$ov, :$ex, *%opts) {
336  
-        if $ex && $pat.^does(Callable) {
  336
+        if $ex && nqp::istype($pat, Callable) {
337 337
             gather {
338 338
                 my $m := self.ll-match($pat, |%opts);
339 339
                 if $m {
@@ -383,7 +383,7 @@ my class Str does Stringy {
383 383
         %opts<p> = $p if $p.defined;
384 384
         my @matches := self.match-list($pat, :g($g || $x || $nth), :$ov, :$ex, |%opts);
385 385
         if $nth.defined {
386  
-            if $nth.^does(Positional) {
  386
+            if nqp::istype($nth, Positional) {
387 387
                 my @nth-monotonic := gather {
388 388
                     my $max = 0;
389 389
                     for $nth.list {
@@ -405,12 +405,12 @@ my class Str does Stringy {
405 405
             }
406 406
         }
407 407
         if $x.defined {
408  
-            if $x.^isa(Int) {
  408
+            if nqp::istype($x, Int) {
409 409
                 @matches.gimme($x) == $x
410 410
                     ?? @matches[^$x]
411 411
                     !! ().list;
412 412
             }
413  
-            elsif $x.^isa(Range) {
  413
+            elsif nqp::istype($x, Range) {
414 414
                 my $real-max := $x.excludes_max ?? $x.max - 1 !! $x.max;
415 415
                 @matches.gimme($real-max) ~~ $x
416 416
                     ?? @matches[^$real-max].list
@@ -472,7 +472,7 @@ my class Str does Stringy {
472 472
 
473 473
     multi method split(Str:D: Regex $pat, $limit = *, :$all) {
474 474
         return ().list if $limit ~~ Numeric && $limit <= 0;
475  
-        my @matches = $limit.^isa(Whatever)
  475
+        my @matches = nqp::istype($limit, Whatever)
476 476
                         ?? self.match($pat, :g)
477 477
                         !! self.match($pat, :x(1..$limit-1), :g);
478 478
         gather {
@@ -732,7 +732,7 @@ my class Str does Stringy {
732 732
     }
733 733
 
734 734
     # Negative values and Whatever-* do outdent
735  
-    multi method indent($steps where { .^isa(Whatever) || .^isa(Int) && $_ < 0 }) {
  735
+    multi method indent($steps where { nqp::istype($_, Whatever) || nqp::istype($_, Int) && $_ < 0 }) {
736 736
         # Loop through all lines to get as much info out of them as possible
737 737
         my @lines = self.comb(/:r ^^ \N* \n?/).map({
738 738
             # Split the line into indent and content

0 notes on commit f524138

Please sign in to comment.
Something went wrong with that request. Please try again.