VariableTableEntry[] oldTable = vTable; int oldCapacity; if ((oldCapacity = oldTable.length) >= MAXIMUM_CAPACITY) { return oldTable; } int newCapacity = oldCapacity << 1; VariableTableEntry[] newTable = new VariableTableEntry[newCapacity]; vTableThreshold = (int)(newCapacity * LOAD_FACTOR); int sizeMask = newCapacity - 1; VariableTableEntry e; for (int i = oldCapacity; --i >= 0; ) { // We need to guarantee that any existing reads of old Map can // proceed. So we cannot yet null out each bin. e = oldTable[i]; if (e != null) { VariableTableEntry next = e.next; int idx = e.hash & sizeMask; // Single node on list if (next == null) newTable[idx] = e; else { // Reuse trailing consecutive sequence at same slot VariableTableEntry lastRun = e; int lastIdx = idx; for (VariableTableEntry last = next; last != null; last = last.next) { int k = last.hash & sizeMask; if (k != lastIdx) { lastIdx = k; lastRun = last; } } newTable[lastIdx] = lastRun; // Clone all remaining nodes for (VariableTableEntry p = e; p != lastRun; p = p.next) { int k = p.hash & sizeMask; VariableTableEntry m = new VariableTableEntry(p.hash, p.name, p.value, newTable[k]); newTable[k] = m; } } } } vTable = newTable; return newTable;
SymbolEntry[] oldTable = symbolTable; int oldCapacity; if ((oldCapacity = oldTable.length) >= MAXIMUM_CAPACITY) { return oldTable; } int newCapacity = oldCapacity << 1; SymbolEntry[] newTable = new SymbolEntry[newCapacity]; threshold = (int)(newCapacity * loadFactor); int sizeMask = newCapacity - 1; SymbolEntry e; for (int i = oldCapacity; --i >= 0; ) { // We need to guarantee that any existing reads of old Map can // proceed. So we cannot yet null out each bin. e = oldTable[i]; if (e != null) { SymbolEntry next = e.next; int idx = e.hash & sizeMask; // Single node on list if (next == null) newTable[idx] = e; else { // Reuse trailing consecutive sequence at same slot SymbolEntry lastRun = e; int lastIdx = idx; for (SymbolEntry last = next; last != null; last = last.next) { int k = last.hash & sizeMask; if (k != lastIdx) { lastIdx = k; lastRun = last; } } newTable[lastIdx] = lastRun; // Clone all remaining nodes for (SymbolEntry p = e; p != lastRun; p = p.next) { int k = p.hash & sizeMask; SymbolEntry n = newTable[k]; newTable[k] = new SymbolEntry(p.hash, p.name, p.symbol, n); } } } } symbolTable = newTable; return newTable;
Clone fragments detected by clone detection tool
File path: /jruby-1.4.0/src/org/jruby/runtime/builtin/InstanceVariableTable.java File path: /jruby-1.4.0/src/org/jruby/RubySymbol.java
Method name: VariableTableEntry[] rehash() Method name: SymbolEntry[] rehash()
Number of AST nodes: 30 Number of AST nodes: 30
1
VariableTableEntry[] oldTable = vTable;
1
SymbolEntry[] oldTable = symbolTable;
2
        int oldCapacity;
2
            int oldCapacity;
3
        if ((oldCapacity = oldTable.length) >= MAXIMUM_CAPACITY) {
3
            if ((oldCapacity = oldTable.length) >= MAXIMUM_CAPACITY) {
4
            return oldTable;
4
                return oldTable;
5
        }
5
        
6
    }
7
            
6
        int newCapacity = oldCapacity << 1;
8
            int newCapacity = oldCapacity << 1;
7
        VariableTableEntry[] newTable = new VariableTableEntry[newCapacity];
9
            SymbolEntry[] newTable = new SymbolEntry[newCapacity];
8
        vTableThreshold = (int)(newCapacity * LOAD_FACTOR);
10
            threshold = (int)(newCapacity * 
11
loadFactor);
9
        int sizeMask = newCapacity - 1;
12
            int sizeMask = newCapacity - 1;
10
        VariableTableEntry e;
13
            SymbolEntry e;
11
        for (int i = oldCapacity; --i >= 0; ) {
14
            for (int i = oldCapacity; --i >= 0; ) {
12
            // We need to guarantee that any existing reads of old Map can
15
                // We need to guarantee that any existing reads of old Map can
13
            //  proceed. So we cannot yet null out each bin.
16
                //  proceed. So we cannot yet null out each bin.
14
            e = oldTable[i];
17
                e = oldTable[i];
15
            if (e != null) {
18
                if (e != null) {
16
                VariableTableEntry next = e.next;
19
                    SymbolEntry next = e.next;
17
                int idx = e.hash & sizeMask;
20
                    int idx = e.hash & sizeMask;
18
                //  Single node on list
21
                    //  Single node on list
19
                if (next == null)
22
                    if (next == null)
20
                    newTable[idx] = e;
23
                        newTable[idx] = e;
21
                else {
24
                    else {
22
                    // Reuse trailing consecutive sequence at same slot
25
                        // Reuse trailing consecutive sequence at same slot
23
                    VariableTableEntry lastRun = e;
26
                        SymbolEntry lastRun = e;
24
                    int lastIdx = idx;
27
                        int lastIdx = idx;
25
                    for (VariableTableEntry last = next;
28
                        for (SymbolEntry last = next;
26
                         last != null;
29
                             last != null;
27
                         last = last.next) {
30
                             last = last.next) {
28
                        int k = last.hash & sizeMask;
31
                            int k = last.hash & sizeMask;
29
                        if (k != lastIdx) {
32
                            if (k != lastIdx) {
30
                            lastIdx = k;
33
                                lastIdx = k;
31
                            lastRun = last;
34
                                lastRun = last;
32
                        }
35
                        
36
    }
33
                    }
37
                      
38
  }
34
                    newTable[lastIdx] = lastRun;
39
                        newTable[lastIdx] = lastRun;
35
                    // Clone all remaining nodes
40
                        // Clone all remaining nodes
36
                    for (VariableTableEntry p = e; p != lastRun; p = p.next) {
41
                        for (SymbolEntry p = e; p != lastRun; p = p.next) {
37
                        int k = p.hash & sizeMask;
42
                            int k = p.hash & sizeMask;
38
                        VariableTableEntry m = new VariableTable
43
                            SymbolEntry n = newTable[k];
39
Entry(p.hash, p.name, p.value, newTable[k]);
44
                            newTable[k] = new SymbolEntry(p.hash, p.name, p.symbol, n);
40
                        newTable[k] = m;
45
                        }
41
                    }
46
                    }
42
                }
47
                }
43
            }
48
            }
44
        }
49
        
45
        vTable = newTable;
50
    symbolTable = newTable;
46
        return newTable;
51
            return newTable;
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.9
Clones locationClones are in different classes
Number of node comparisons14
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements3
    Number of unmapped statements in the first code fragment1
    Number of unmapped statements in the second code fragment1
    Time elapsed for statement mapping (ms)43.4
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    20
    int k = last.hash & sizeMask;
    20
    int k = last.hash & sizeMask;
    20
    int k = last.hash & sizeMask;
    Differences
    Expression1Expression2Difference
    org.jruby.runtime.builtin.InstanceVariableTable.VariableTableEntryorg.jruby.RubySymbol.SymbolTable.SymbolEntryVARIABLE_TYPE_MISMATCH
    Preondition Violations
    Type org.jruby.runtime.builtin.InstanceVariableTable.VariableTableEntry of variable last does not match with type org.jruby.RubySymbol.SymbolTable.SymbolEntry of variable last
    • Make classes org.jruby.runtime.builtin.InstanceVariableTable.VariableTableEntry and org.jruby.RubySymbol.SymbolTable.SymbolEntry extend a common superclass
    20
    int k = last.hash & sizeMask;
    21
    if (k != lastIdx)
    21
    if (k != lastIdx)
    22
    lastIdx = k;
    22
    lastIdx = k;
                                      
    23
    lastRun = last;
    23
    lastRun = last;
                                      
    Precondition Violations (1)
    Row Violation
    1Type org.jruby.runtime.builtin.InstanceVariableTable.VariableTableEntry of variable last does not match with type org.jruby.RubySymbol.SymbolTable.SymbolEntry of variable last