3v4l.org

run code in 300+ PHP versions simultaneously
<?php function doCharDiff($from_text, $to_text) { $result = []; $jobs = [[0, strlen($from_text), 0, strlen($to_text)]]; while ($job = array_pop($jobs)) { // get the segments which must be diff'ed list($from_segment_start, $from_segment_end, $to_segment_start, $to_segment_end) = $job; $from_segment_len = $from_segment_end - $from_segment_start; $to_segment_len = $to_segment_end - $to_segment_start; // catch easy cases first if (!$from_segment_len || !$to_segment_len) { if ($from_segment_len) $result[$from_segment_start * 4 + 0] = new FineDiffDeleteOp($from_segment_len); else if ($to_segment_len) $result[$from_segment_start * 4 + 1] = new FineDiffInsertOp(substr($to_text, $to_segment_start, $to_segment_len)); continue; } if ($from_segment_len >= $to_segment_len) { $copy_len = $to_segment_len; while ($copy_len) { $to_copy_start = $to_segment_start; $to_copy_start_max = $to_segment_end - $copy_len; while ($to_copy_start <= $to_copy_start_max) { $from_copy_start = strpos(substr($from_text, $from_segment_start, $from_segment_len), substr($to_text, $to_copy_start, $copy_len)); if ($from_copy_start !== false) { $from_copy_start += $from_segment_start; break 2; } $to_copy_start++; } $copy_len--; } } else { $copy_len = $from_segment_len; while ($copy_len) { $from_copy_start = $from_segment_start; $from_copy_start_max = $from_segment_end - $copy_len; while ($from_copy_start <= $from_copy_start_max) { $to_copy_start = strpos(substr($to_text, $to_segment_start, $to_segment_len), substr($from_text, $from_copy_start, $copy_len)); if ($to_copy_start !== false) { $to_copy_start += $to_segment_start; break 2; } $from_copy_start++; } $copy_len--; } } // match found if ($copy_len) { $jobs[] = [$from_segment_start, $from_copy_start, $to_segment_start, $to_copy_start]; $result[$from_copy_start * 4 + 2] = new FineDiffCopyOp($copy_len); $jobs[] = [$from_copy_start + $copy_len, $from_segment_end, $to_copy_start + $copy_len, $to_segment_end]; } // no match, so delete all, insert all else { $result[$from_segment_start * 4] = new FineDiffReplaceOp($from_segment_len, substr($to_text, $to_segment_start, $to_segment_len)); } } ksort($result, SORT_NUMERIC); return array_values($result); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NnOk1
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E > > RETURN                                                   1

Function dochardiff:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 152
Branch analysis from position: 152
2 jumps found. (Code = 44) Position 1 = 157, Position 2 = 12
Branch analysis from position: 157
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 54
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 40
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 152
Branch analysis from position: 152
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 53
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 152
Branch analysis from position: 152
Branch analysis from position: 53
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 87
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 58
Branch analysis from position: 86
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
2 jumps found. (Code = 43) Position 1 = 118, Position 2 = 140
Branch analysis from position: 118
1 jumps found. (Code = 42) Position 1 = 152
Branch analysis from position: 152
Branch analysis from position: 140
2 jumps found. (Code = 44) Position 1 = 157, Position 2 = 12
Branch analysis from position: 157
Branch analysis from position: 12
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 82
Branch analysis from position: 82
2 jumps found. (Code = 44) Position 1 = 84, Position 2 = 62
Branch analysis from position: 84
2 jumps found. (Code = 44) Position 1 = 86, Position 2 = 58
Branch analysis from position: 86
Branch analysis from position: 58
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 79, Position 2 = 81
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
Branch analysis from position: 81
2 jumps found. (Code = 44) Position 1 = 84, Position 2 = 62
Branch analysis from position: 84
Branch analysis from position: 62
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 116
Branch analysis from position: 116
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 89
Branch analysis from position: 117
Branch analysis from position: 89
1 jumps found. (Code = 42) Position 1 = 113
Branch analysis from position: 113
2 jumps found. (Code = 44) Position 1 = 115, Position 2 = 93
Branch analysis from position: 115
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 89
Branch analysis from position: 117
Branch analysis from position: 89
Branch analysis from position: 93
2 jumps found. (Code = 43) Position 1 = 110, Position 2 = 112
Branch analysis from position: 110
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 112
2 jumps found. (Code = 44) Position 1 = 115, Position 2 = 93
Branch analysis from position: 115
Branch analysis from position: 93
Branch analysis from position: 30
filename:       /in/NnOk1
function name:  doCharDiff
number of ops:  166
compiled vars:  !0 = $from_text, !1 = $to_text, !2 = $result, !3 = $jobs, !4 = $job, !5 = $from_segment_start, !6 = $from_segment_end, !7 = $to_segment_start, !8 = $to_segment_end, !9 = $from_segment_len, !10 = $to_segment_len, !11 = $copy_len, !12 = $to_copy_start, !13 = $to_copy_start_max, !14 = $from_copy_start, !15 = $from_copy_start_max
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        INIT_ARRAY                                       ~17     0
          4        STRLEN                                           ~18     !0
          5        ADD_ARRAY_ELEMENT                                ~17     ~18
          6        ADD_ARRAY_ELEMENT                                ~17     0
          7        STRLEN                                           ~19     !1
          8        ADD_ARRAY_ELEMENT                                ~17     ~19
          9        INIT_ARRAY                                       ~20     ~17
         10        ASSIGN                                                   !3, ~20
    6    11      > JMP                                                      ->152
    9    12    >   QM_ASSIGN                                        ~22     !4
         13        FETCH_LIST_R                                     $23     ~22, 0
         14        ASSIGN                                                   !5, $23
         15        FETCH_LIST_R                                     $25     ~22, 1
         16        ASSIGN                                                   !6, $25
         17        FETCH_LIST_R                                     $27     ~22, 2
         18        ASSIGN                                                   !7, $27
         19        FETCH_LIST_R                                     $29     ~22, 3
         20        ASSIGN                                                   !8, $29
         21        FREE                                                     ~22
   10    22        SUB                                              ~31     !6, !5
         23        ASSIGN                                                   !9, ~31
   11    24        SUB                                              ~33     !8, !7
         25        ASSIGN                                                   !10, ~33
   14    26        BOOL_NOT                                         ~35     !9
         27      > JMPNZ_EX                                         ~35     ~35, ->30
         28    >   BOOL_NOT                                         ~36     !10
         29        BOOL                                             ~35     ~36
         30    > > JMPZ                                                     ~35, ->54
   16    31    > > JMPZ                                                     !9, ->40
   17    32    >   MUL                                              ~37     !5, 4
         33        ADD                                              ~38     ~37, 0
         34        NEW                                              $40     'FineDiffDeleteOp'
         35        SEND_VAR_EX                                              !9
         36        DO_FCALL                                      0          
         37        ASSIGN_DIM                                               !2, ~38
         38        OP_DATA                                                  $40
         39      > JMP                                                      ->53
   18    40    > > JMPZ                                                     !10, ->53
   19    41    >   MUL                                              ~42     !5, 4
         42        ADD                                              ~43     ~42, 1
         43        NEW                                              $45     'FineDiffInsertOp'
         44        INIT_FCALL                                               'substr'
         45        SEND_VAR                                                 !1
         46        SEND_VAR                                                 !7
         47        SEND_VAR                                                 !10
         48        DO_ICALL                                         $46     
         49        SEND_VAR_NO_REF_EX                                       $46
         50        DO_FCALL                                      0          
         51        ASSIGN_DIM                                               !2, ~43
         52        OP_DATA                                                  $45
   21    53    > > JMP                                                      ->152
   24    54    >   IS_SMALLER_OR_EQUAL                                      !10, !9
         55      > JMPZ                                                     ~48, ->87
   26    56    >   ASSIGN                                                   !11, !10
   27    57      > JMP                                                      ->85
   29    58    >   ASSIGN                                                   !12, !7
   30    59        SUB                                              ~51     !8, !11
         60        ASSIGN                                                   !13, ~51
   31    61      > JMP                                                      ->82
   33    62    >   INIT_FCALL                                               'strpos'
         63        INIT_FCALL                                               'substr'
         64        SEND_VAR                                                 !0
         65        SEND_VAR                                                 !5
         66        SEND_VAR                                                 !9
         67        DO_ICALL                                         $53     
         68        SEND_VAR                                                 $53
         69        INIT_FCALL                                               'substr'
         70        SEND_VAR                                                 !1
         71        SEND_VAR                                                 !12
         72        SEND_VAR                                                 !11
         73        DO_ICALL                                         $54     
         74        SEND_VAR                                                 $54
         75        DO_ICALL                                         $55     
         76        ASSIGN                                                   !14, $55
   34    77        TYPE_CHECK                                  1018          !14
         78      > JMPZ                                                     ~57, ->81
   36    79    >   ASSIGN_OP                                     1          !14, !5
   37    80      > JMP                                                      ->86
   39    81    >   PRE_INC                                                  !12
   31    82    >   IS_SMALLER_OR_EQUAL                                      !12, !13
         83      > JMPNZ                                                    ~60, ->62
   41    84    >   PRE_DEC                                                  !11
   27    85    > > JMPNZ                                                    !11, ->58
         86    > > JMP                                                      ->117
   46    87    >   ASSIGN                                                   !11, !9
   47    88      > JMP                                                      ->116
   49    89    >   ASSIGN                                                   !14, !5
   50    90        SUB                                              ~64     !6, !11
         91        ASSIGN                                                   !15, ~64
   51    92      > JMP                                                      ->113
   53    93    >   INIT_FCALL                                               'strpos'
         94        INIT_FCALL                                               'substr'
         95        SEND_VAR                                                 !1
         96        SEND_VAR                                                 !7
         97        SEND_VAR                                                 !10
         98        DO_ICALL                                         $66     
         99        SEND_VAR                                                 $66
        100        INIT_FCALL                                               'substr'
        101        SEND_VAR                                                 !0
        102        SEND_VAR                                                 !14
        103        SEND_VAR                                                 !11
        104        DO_ICALL                                         $67     
        105        SEND_VAR                                                 $67
        106        DO_ICALL                                         $68     
        107        ASSIGN                                                   !12, $68
   54   108        TYPE_CHECK                                  1018          !12
        109      > JMPZ                                                     ~70, ->112
   56   110    >   ASSIGN_OP                                     1          !12, !7
   57   111      > JMP                                                      ->117
   59   112    >   PRE_INC                                                  !14
   51   113    >   IS_SMALLER_OR_EQUAL                                      !14, !15
        114      > JMPNZ                                                    ~73, ->93
   61   115    >   PRE_DEC                                                  !11
   47   116    > > JMPNZ                                                    !11, ->89
   65   117    > > JMPZ                                                     !11, ->140
   67   118    >   INIT_ARRAY                                       ~76     !5
        119        ADD_ARRAY_ELEMENT                                ~76     !14
        120        ADD_ARRAY_ELEMENT                                ~76     !7
        121        ADD_ARRAY_ELEMENT                                ~76     !12
        122        ASSIGN_DIM                                               !3
        123        OP_DATA                                                  ~76
   68   124        MUL                                              ~77     !14, 4
        125        ADD                                              ~78     ~77, 2
        126        NEW                                              $80     'FineDiffCopyOp'
        127        SEND_VAR_EX                                              !11
        128        DO_FCALL                                      0          
        129        ASSIGN_DIM                                               !2, ~78
        130        OP_DATA                                                  $80
   69   131        ADD                                              ~83     !14, !11
        132        INIT_ARRAY                                       ~84     ~83
        133        ADD_ARRAY_ELEMENT                                ~84     !6
        134        ADD                                              ~85     !12, !11
        135        ADD_ARRAY_ELEMENT                                ~84     ~85
        136        ADD_ARRAY_ELEMENT                                ~84     !8
        137        ASSIGN_DIM                                               !3
        138        OP_DATA                                                  ~84
        139      > JMP                                                      ->152
   74   140    >   MUL                                              ~86     !5, 4
        141        NEW                                              $88     'FineDiffReplaceOp'
        142        SEND_VAR_EX                                              !9
        143        INIT_FCALL                                               'substr'
        144        SEND_VAR                                                 !1
        145        SEND_VAR                                                 !7
        146        SEND_VAR                                                 !10
        147        DO_ICALL                                         $89     
        148        SEND_VAR_NO_REF_EX                                       $89
        149        DO_FCALL                                      0          
        150        ASSIGN_DIM                                               !2, ~86
        151        OP_DATA                                                  $88
    6   152    >   INIT_FCALL                                               'array_pop'
        153        SEND_REF                                                 !3
        154        DO_ICALL                                         $91     
        155        ASSIGN                                           ~92     !4, $91
        156      > JMPNZ                                                    ~92, ->12
   77   157    >   INIT_FCALL                                               'ksort'
        158        SEND_REF                                                 !2
        159        SEND_VAL                                                 1
        160        DO_ICALL                                                 
   78   161        INIT_FCALL                                               'array_values'
        162        SEND_VAR                                                 !2
        163        DO_ICALL                                         $94     
        164      > RETURN                                                   $94
   79   165*     > RETURN                                                   null

End of function dochardiff

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.17 ms | 1412 KiB | 23 Q