int currentByte = 0; int padLength = 0; if (occurrences > lCurElemString.length()) { padLength = occurrences - lCurElemString.length() + 1; occurrences = lCurElemString.length(); } for (int i = 0; i < occurrences;) { byte currentChar = (byte)lCurElemString.charAt(i++); if (Character.isJavaIdentifierStart(currentChar)) { //this test may be too lax but it is the same as in MRI currentByte |= ((currentChar & 15) + 9) & 15; } else { currentByte |= currentChar & 15; } if ((i & 1) != 0) { currentByte <<= 4; } else { result.append((byte) (currentByte & 0xff)); currentByte = 0; } } if ((occurrences & 1) != 0) { result.append((byte) (currentByte & 0xff)); if(padLength > 0) { padLength--; } } result.length(result.length() + padLength / 2);
int currentByte = 0; int padLength = 0; if (occurrences > lCurElemString.length()) { padLength = occurrences - lCurElemString.length() + 1; occurrences = lCurElemString.length(); } for (int i = 0; i < occurrences;) { byte currentChar = (byte)lCurElemString.charAt(i++); if (Character.isJavaIdentifierStart(currentChar)) { //this test may be too lax but it is the same as in MRI currentByte |= (((currentChar & 15) + 9) & 15) << 4; } else { currentByte |= (currentChar & 15) << 4; } if ((i & 1) != 0) { currentByte >>= 4; } else { result.append((byte) (currentByte & 0xff)); currentByte = 0; } } if ((occurrences & 1) != 0) { result.append((byte) (currentByte & 0xff)); if(padLength > 0) { padLength--; } } result.length(result.length() + padLength / 2);
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: 19 Number of AST nodes: 19
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() + 1;
4
                                        padLength = occurrences - lCurElemString.length() + 1;
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
                                        byte currentChar = (byte)lCurElemString.charAt(i++);
8
                                        byte currentChar = (byte)lCurElemString.charAt(i++);
9
                                        if (Character.isJavaIdentifierStart(currentChar)) {
9
                                        if (Character.isJavaIdentifierStart(currentChar)) {
10
                                            //this test may be too lax but it is the same as in MRI
10
                                            //this test may be too lax but it is the same as in MRI
11
                                            currentByte |= ((currentChar & 15) + 9) & 15;
11
                                            currentByte |= (((currentChar & 15) + 9) & 15) << 4;
12
                                        } else {
12
                                        } else {
13
                                            currentByte |= currentChar & 15;
13
                                            currentByte |= (currentChar & 15) << 4;
14
                                        }
14
                                        }
15
                                        if ((i & 1) != 0) {
15
                                        if ((i & 1) != 0) {
16
                                            currentByte &lt;&lt;= 4;
16
                                            currentByte &gt;&gt;= 4;
17
                                        } else {
17
                                        } else {
18
                                            result.append((byte) (currentByte & 0xff));
18
                                            result.append((byte) (currentByte & 0xff));
19
                                            currentByte = 0;
19
                                            currentByte = 0;
20
                                        }
20
                                        }
21
                                    }
21
                                    }
22
                                    if ((occurrences & 1) != 0) {
22
                                    if ((occurrences & 1) != 0) {
23
                                        result.append((byte) (currentByte & 0xff));
23
                                        result.append((byte) (currentByte & 0xff));
24
                                        if(padLength > 0) {
24
                                        if(padLength > 0) {
25
                                            padLength--;
25
                                            padLength--;
26
                                        }
26
                                        }
27
                                    }
27
                                    }
28
                                    result.length(result.length() + padLength / 2);
28
                                    result.length(result.length() + padLength / 2);
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)4.5
Clones locationClones are in the same method
Number of node comparisons83
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements16
    Number of unmapped statements in the first code fragment3
    Number of unmapped statements in the second code fragment3
    Time elapsed for statement mapping (ms)16.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    143
    int currentByte = 0;
    122
    int currentByte = 0;
    144
    int padLength = 0;
    123
    int padLength = 0;
    145
    if (occurrences > lCurElemString.length())
    124
    if (occurrences > lCurElemString.length())
    146
    padLength = occurrences - lCurElemString.length() + 1;
    125
    padLength = occurrences - lCurElemString.length() + 1;
    147
    occurrences = lCurElemString.length();
    126
    occurrences = lCurElemString.length();
    148
    for (int i = 0; i < occurrences; )
    127
    for (int i = 0; i < occurrences; )
    149
    byte currentChar = (byte)lCurElemString.charAt(i++);
    128
    byte currentChar = (byte)lCurElemString.charAt(i++);
    150
    if (Character.isJavaIdentifierStart(currentChar))
    129
    if (Character.isJavaIdentifierStart(currentChar))
                                                                                                                  
    130
    currentByte |= (((currentChar & 15) + 9) & 15) << 4;
    Preondition Violations
    Unmatched statement currentByte|=(((currentChar & 15) + 9) & 15) << 4; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    130
    currentByte |= (((currentChar & 15) + 9) & 15) << 4;
    151
    currentByte |= ((currentChar & 15) + 9) & 15;
    151
    currentByte |= ((currentChar & 15) + 9) & 15;
    Preondition Violations
    Unmatched statement currentByte|=((currentChar & 15) + 9) & 15; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                                                    
    else
            
                                                                                        
    131
    currentByte |= (currentChar & 15) << 4;
    Preondition Violations
    Unmatched statement currentByte|=(currentChar & 15) << 4; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    131
    currentByte |= (currentChar & 15) << 4;
    152
    currentByte |= currentChar & 15;
    152
    currentByte |= currentChar & 15;
    Preondition Violations
    Unmatched statement currentByte|=currentChar & 15; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                          
    153
    if ((i & 1) != 0)
    132
    if ((i & 1) != 0)
                                              
    133
    currentByte >>= 4;
    154
    currentByte <<= 4;
                                              
    else
    else
    155
    result.append((byte)(currentByte & 0xff));
    134
    result.append((byte)(currentByte & 0xff));
    156
    currentByte = 0;
    135
    currentByte = 0;
    157
    if ((occurrences & 1) != 0)
    136
    if ((occurrences & 1) != 0)
    158
    result.append((byte)(currentByte & 0xff));
    137
    result.append((byte)(currentByte & 0xff));
    159
    if (padLength > 0)
    138
    if (padLength > 0)
    160
    padLength--;
    139
    padLength--;
    161
    result.length(result.length() + padLength / 2);
    140
    result.length(result.length() + padLength / 2);
    Precondition Violations (5)
    Row Violation
    1Unmatched statement currentByte|=(((currentChar & 15) + 9) & 15) << 4; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement currentByte|=((currentChar & 15) + 9) & 15; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement currentByte|=(currentChar & 15) << 4; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Unmatched statement currentByte|=currentChar & 15; cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    5Clone fragment #1 returns variables currentByte, currentChar , while Clone fragment #2 returns variables currentByte, currentChar