int currentByte = 0; int padLength = 0; if (occurrences > lCurElemString.length()) { padLength = (occurrences - lCurElemString.length()) / 2 + occurrences % 2; occurrences = lCurElemString.length(); } for (int i = 0; i < occurrences;) { if ((lCurElemString.charAt(i++) & 1) != 0) {//if the low bit is set currentByte |= 128; //set the high bit of the result } if ((i & 7) == 0) { result.append((byte) (currentByte & 0xff)); currentByte = 0; continue; } //if the index is not a multiple of 8, we are not on a byte boundary currentByte >>= 1; //shift the byte } if ((occurrences & 7) != 0) { //if the length is not a multiple of 8 currentByte >>= 7 - (occurrences & 7); //we need to pad the last byte result.append((byte) (currentByte & 0xff)); } //do some padding, I don't understand the padding strategy result.length(result.length() + padLength);
int currentByte = 0; int padLength = 0; if (occurrences > lCurElemString.length()) { padLength = (occurrences - lCurElemString.length()) / 2 + occurrences % 2; occurrences = lCurElemString.length(); } for (int i = 0; i < occurrences;) { currentByte |= lCurElemString.charAt(i++) & 1; // we filled up current byte; append it and create next one if ((i & 7) == 0) { result.append((byte) (currentByte & 0xff)); currentByte = 0; continue; } //if the index is not a multiple of 8, we are not on a byte boundary currentByte <<= 1; } if ((occurrences & 7) != 0) { //if the length is not a multiple of 8 currentByte <<= 7 - (occurrences & 7); //we need to pad the last byte result.append((byte) (currentByte & 0xff)); } result.length(result.length() + padLength);
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/util/Pack.java File path: /jruby-1.4.0/src/org/jruby/util/Pack.java
Method name: RubyString pack(Ruby, RubyArray, ByteList) Method name: RubyString pack(Ruby, RubyArray, ByteList)
Number of AST nodes: 17 Number of AST nodes: 16
1
int currentByte = 0;
1
int currentByte = 0;
2
                                    int padLength = 0;
2
                                    int padLength = 0;
3
                                    if (occurrences > lCurElemString.length()) {
3
                                    if (occurrences > lCurElemString.length()) {
4
                                        padLength = (occurrences - lCurElemString.length()) / 2 + occurrences % 2;
4
                                        padLength = (occurrences - lCurElemString.length()) / 2 + occurrences % 2;
5
                                        occurrences = lCurElemString.length();
5
                                        occurrences = lCurElemString.length();
6
                                    }
6
                                    }
7
                                    for (int i = 0; i < occurrences;) {
7
                                    for (int i = 0; i < occurrences;) {
8
                                        if ((lCurElemString.charAt(i++) & 1) != 0) {//if the low bit is set
8
                                        currentByte |= lCurElemString.charAt(i++) & 1;
9
                                            currentByte |= 128; //set the high bit of the result
9
                                        // we filled up current byte
10
                                        }
10
; append it and create next one
11
                                        if ((i & 7) == 0) {
11
                                        if ((i & 7) == 0) {
12
                                            result.append((byte) (currentByte & 0xff));
12
                                            result.append((byte) (currentByte & 0xff));
13
                                            currentByte = 0;
13
                                            currentByte = 0;
14
                                            continue;
14
                                            continue;
15
                                        }
15
                                        }
16
                                           //if the index is not a multiple of 8, we are not on a byte boundary
16
                                        //if the index is not a multiple of 8, we are not on a byte boundary
17
                                           currentByte &gt;&gt;= 1; //shift the byte
17
                                        currentByte &lt;&lt;= 1;
18
                                    }
18
                                    }
19
                                    if ((occurrences & 7) != 0) { //if the length is not a multiple of 8
19
                                    if ((occurrences & 7) != 0) { //if the length is not a multiple of 8
20
                                        currentByte &gt;&gt;= 7 - (occurrences & 7); //we need to pad the last byte
20
                                        currentByte &lt;&lt;= 7 - (occurrences & 7); //we need to pad the last byte
21
                                        result.append((byte) (currentByte & 0xff));
21
                                        result.append((byte) (currentByte & 0xff));
22
                                    }
22
                                    }
23
                                    //do some padding, I don't understand the padding strategy
24
                                    result.length(result.length() + padLength);
23
                                    result.length(result.length() + padLength);
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)3.4
Clones locationClones are in the same method
Number of node comparisons64
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements13
    Number of unmapped statements in the first code fragment4
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)13.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    85
    int currentByte = 0;
    104
    int currentByte = 0;
    86
    int padLength = 0;
    105
    int padLength = 0;
    87
    if (occurrences > lCurElemString.length())
    106
    if (occurrences > lCurElemString.length())
    88
    padLength = (occurrences - lCurElemString.length()) / 2 + occurrences % 2;
    107
    padLength = (occurrences - lCurElemString.length()) / 2 + occurrences % 2;
    89
    occurrences = lCurElemString.length();
    108
    occurrences = lCurElemString.length();
    90
    for (int i = 0; i < occurrences; )
    109
    for (int i = 0; i < occurrences; )
    91
    if ((lCurElemString.charAt(i++) & 1) != 0)
    91
    if ((lCurElemString.charAt(i++) & 1) != 0)
    Preondition Violations
    Unmatched statement if((lCurElemString.charAt(i++) & 1) != 0) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                              
    92
    currentByte |= 128;
    92
    currentByte |= 128;
    Preondition Violations
    Unmatched statement currentByte|=128; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                              
                                                                                                      
    110
    currentByte |= lCurElemString.charAt(i++) & 1;
    Preondition Violations
    Unmatched statement currentByte|=lCurElemString.charAt(i++) & 1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    110
    currentByte |= lCurElemString.charAt(i++) & 1;
    93
    if ((i & 7) == 0)
    111
    if ((i & 7) == 0)
    94
    result.append((byte)(currentByte & 0xff));
    112
    result.append((byte)(currentByte & 0xff));
    95
    currentByte = 0;
    113
    currentByte = 0;
    96
    continue;
    114
    continue;
    97
    currentByte >>= 1;
    97
    currentByte >>= 1;
    Preondition Violations
    Unmatched statement currentByte>>=1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
                                              
    115
    currentByte <<= 1;
    98
    if ((occurrences & 7) != 0)
    116
    if ((occurrences & 7) != 0)
    99
    currentByte >>= 7 - (occurrences & 7);
    99
    currentByte >>= 7 - (occurrences & 7);
    Preondition Violations
    Unmatched statement currentByte>>=7 - (occurrences & 7); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                    
                                                                                      
    117
    currentByte <<= 7 - (occurrences & 7);
    Preondition Violations
    Unmatched statement currentByte<<=7 - (occurrences & 7); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    117
    currentByte <<= 7 - (occurrences & 7);
    100
    result.append((byte)(currentByte & 0xff));
    118
    result.append((byte)(currentByte & 0xff));
    101
    result.length(result.length() + padLength);
    119
    result.length(result.length() + padLength);
    Precondition Violations (7)
    Row Violation
    1Unmatched statement if((lCurElemString.charAt(i++) & 1) != 0) cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement currentByte|=128; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement currentByte|=lCurElemString.charAt(i++) & 1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement currentByte>>=1; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Unmatched statement currentByte>>=7 - (occurrences & 7); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement currentByte<<=7 - (occurrences & 7); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Clone fragment #1 returns variables i, currentByte, occurrences , while Clone fragment #2 returns variables currentByte, i, occurrences