args = Arity.scanArgs(recv.getRuntime(),args,0,2); long crc = 0; ByteList bytes = null; if (!args[0].isNil()) bytes = args[0].convertToString().getByteList(); if (!args[1].isNil()) crc = RubyNumeric.num2long(args[1]); CRC32Ext ext = new CRC32Ext((int)crc); if (bytes != null) { ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length()); } return recv.getRuntime().newFixnum(ext.getValue());
args = Arity.scanArgs(recv.getRuntime(),args,0,2); int adler = 1; ByteList bytes = null; if (!args[0].isNil()) bytes = args[0].convertToString().getByteList(); if (!args[1].isNil()) adler = RubyNumeric.fix2int(args[1]); Adler32Ext ext = new Adler32Ext(adler); if (bytes != null) { ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length()); // it's safe since adler.update doesn't modify the array } return recv.getRuntime().newFixnum(ext.getValue());
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/RubyZlib.java File path: /jruby-1.4.0/src/org/jruby/RubyZlib.java
Method name: IRubyObject crc32(IRubyObject, IRubyObject[]) Method name: IRubyObject adler32(IRubyObject, IRubyObject[])
Number of AST nodes: 11 Number of AST nodes: 11
1
args = Arity.scanArgs(recv.getRuntime(),args,0,2);
1
args = Arity.scanArgs(recv.getRuntime(),args,0,2);
2
        long crc = 0;
2
        int adler = 1;
3
        ByteList bytes = null;
3
        ByteList bytes = null;
4
        
5
        if (!args[0].isNil()) bytes = args[0].convertToString().getByteList();
4
        if (!args[0].isNil()) bytes = args[0].convertToString().getByteList();
6
        if (!args[1].isNil()) crc = RubyNumeric.num2long(args[1]);
5
        if (!args[1].isNil()) adler = RubyNumeric.fix2int(args[1]);
7
        CRC32Ext ext = new CRC32Ext((int)crc);
6
        Adler32Ext ext = new Adler32Ext(adler);
8
        if (bytes != null) {
7
        if (bytes != null) {
9
            ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
8
            ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
10
        }
9
 // it's safe since adler.update doesn't modify the array
11
        
10
        }
12
        return recv.getRuntime().newFixnum(ext.getValue());
11
        return recv.getRuntime().newFixnum(ext.getValue());
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.7
Clones locationClones are declared in the same class
Number of node comparisons52
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements8
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)2.0
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    1
    args = Arity.scanArgs(recv.getRuntime(), args, 0, 2);
    1
    args = Arity.scanArgs(recv.getRuntime(), args, 0, 2);
                                  
    2
    int adler = 1;
    2
    long crc = 0;
                                
    3
    ByteList bytes = null;
    3
    ByteList bytes = null;
    4
    if (!args[0].isNil())
    4
    if (!args[0].isNil())
    5
    bytes = args[0].convertToString().getByteList();
    5
    bytes = args[0].convertToString().getByteList();
    6
    if (!args[1].isNil())
    6
    if (!args[1].isNil())
                                                                                
    7
    adler = RubyNumeric.fix2int(args[1]);
    7
    crc = RubyNumeric.num2long(args[1]);
                                                                              
                                                                                    
    8
    Adler32Ext ext = new Adler32Ext(adler);
    8
    CRC32Ext ext = new CRC32Ext((int)crc);
                                                                                  
    9
    if (bytes != null)
    9
    if (bytes != null)
    10
    ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
    10
    ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
    10
    ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
    Differences
    Expression1Expression2Difference
    org.jruby.util.CRC32Extorg.jruby.util.Adler32ExtVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.jruby.util.CRC32Ext of variable ext does not match with type org.jruby.util.Adler32Ext of variable ext
    • Make classes org.jruby.util.CRC32Ext and org.jruby.util.Adler32Ext extend a common superclass
    10
    ext.update(bytes.unsafeBytes(), bytes.begin(), bytes.length());
    11
    return recv.getRuntime().newFixnum(ext.getValue());
    11
    return recv.getRuntime().newFixnum(ext.getValue());
    11
    return recv.getRuntime().newFixnum(ext.getValue());
    Differences
    Expression1Expression2Difference
    org.jruby.util.CRC32Extorg.jruby.util.Adler32ExtVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.jruby.util.CRC32Ext of variable ext does not match with type org.jruby.util.Adler32Ext of variable ext
    • Make classes org.jruby.util.CRC32Ext and org.jruby.util.Adler32Ext extend a common superclass
    11
    return recv.getRuntime().newFixnum(ext.getValue());
    Precondition Violations (2)
    Row Violation
    1Type org.jruby.util.CRC32Ext of variable ext does not match with type org.jruby.util.Adler32Ext of variable ext
    2Type org.jruby.util.CRC32Ext of variable ext does not match with type org.jruby.util.Adler32Ext of variable ext