View | Details | Raw Unified | Return to bug 114855 | Differences between
and this patch

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/codegen/Label.java (-15 / +59 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.codegen;
11
package org.eclipse.jdt.internal.compiler.codegen;
12
12
13
import java.util.Arrays;
14
13
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
15
import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding;
14
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
16
import org.eclipse.jdt.internal.compiler.problem.AbortMethod;
15
17
Lines 43-69 Link Here
43
/**
45
/**
44
 * Add a forward refrence for the array.
46
 * Add a forward refrence for the array.
45
 */
47
 */
46
void addForwardReference(int iPos) {
48
void addForwardReference(int pos) {
47
	int length;
49
	final int count = this.forwardReferenceCount;
48
	if (forwardReferenceCount >= (length = forwardReferences.length))
50
	if (count >= 1) {
49
		System.arraycopy(forwardReferences, 0, (forwardReferences = new int[2*length]), 0, length);
51
		int previousValue = this.forwardReferences[count - 1];
50
	forwardReferences[forwardReferenceCount++] = iPos;
52
		if (previousValue < pos) {
53
			int length;
54
			if (count >= (length = this.forwardReferences.length))
55
				System.arraycopy(this.forwardReferences, 0, (this.forwardReferences = new int[2*length]), 0, length);
56
			this.forwardReferences[this.forwardReferenceCount++] = pos;			
57
		} else if (previousValue > pos) {
58
			int[] refs = this.forwardReferences;
59
			// check for duplicates
60
			for (int i = 0, max = this.forwardReferenceCount; i < max; i++) {
61
				if (refs[i] == pos) return; // already recorded
62
			}
63
			int length;
64
			if (count >= (length = refs.length))
65
				System.arraycopy(refs, 0, (this.forwardReferences = new int[2*length]), 0, length);
66
			this.forwardReferences[this.forwardReferenceCount++] = pos;
67
			Arrays.sort(this.forwardReferences, 0, this.forwardReferenceCount);
68
		}
69
	} else {
70
		int length;
71
		if (count >= (length = this.forwardReferences.length))
72
			System.arraycopy(this.forwardReferences, 0, (this.forwardReferences = new int[2*length]), 0, length);
73
		this.forwardReferences[this.forwardReferenceCount++] = pos;
74
	}
51
}
75
}
52
76
53
/**
77
/**
54
 * Add a forward refrence for the array.
78
 * Add a forward reference for the array.
55
 */
79
 */
56
public void appendForwardReferencesFrom(Label otherLabel) {
80
public void appendForwardReferencesFrom(Label otherLabel) {
57
	int otherCount = otherLabel.forwardReferenceCount;
81
	final int otherCount = otherLabel.forwardReferenceCount;
58
	if (otherCount == 0) return;
82
	if (otherCount == 0) return;
59
	int length = forwardReferences.length;
83
	// need to merge the two sorted arrays of forward references
60
	int neededSpace = otherCount + forwardReferenceCount;
84
	int[] mergedForwardReferences = new int[this.forwardReferenceCount + otherCount];
61
	if (neededSpace >= length){
85
	int indexInMerge = 0;
62
		System.arraycopy(forwardReferences, 0, (forwardReferences = new int[neededSpace]), 0, forwardReferenceCount);
86
	int j = 0;
87
	int i = 0;
88
	int max = this.forwardReferenceCount;
89
	int max2 = otherLabel.forwardReferenceCount;
90
	loop1 : for (; i < max; i++) {
91
		final int value1 = this.forwardReferences[i];
92
		for (; j < max2; j++) {
93
			final int value2 = otherLabel.forwardReferences[j];
94
			if (value1 < value2) {
95
				mergedForwardReferences[indexInMerge++] = value1;
96
				continue loop1;
97
			} else if (value1 == value2) {
98
				mergedForwardReferences[indexInMerge++] = value1;
99
				j++;
100
				continue loop1;
101
			} else {
102
				mergedForwardReferences[indexInMerge++] = value2;
103
			}
104
		}
105
	}
106
	for (; j < max2; j++) {
107
		mergedForwardReferences[indexInMerge++] = otherLabel.forwardReferences[j];
63
	}
108
	}
64
	// append other forward references at the end, so they will get updated as well
109
	this.forwardReferences = mergedForwardReferences;
65
	System.arraycopy(otherLabel.forwardReferences, 0, forwardReferences, forwardReferenceCount, otherCount);
110
	this.forwardReferenceCount = indexInMerge;
66
	forwardReferenceCount = neededSpace;
67
}
111
}
68
112
69
/*
113
/*
Lines 172-178 Link Here
172
				codeStream.classFileOffset -= 3;
216
				codeStream.classFileOffset -= 3;
173
				forwardReferenceCount--;
217
				forwardReferenceCount--;
174
				// also update the PCs in the related debug attributes
218
				// also update the PCs in the related debug attributes
175
				/** OLD CODE
219
				/* OLD CODE
176
					int index = codeStream.pcToSourceMapSize - 1;
220
					int index = codeStream.pcToSourceMapSize - 1;
177
						while ((index >= 0) && (codeStream.pcToSourceMap[index][1] == oldPosition)) {
221
						while ((index >= 0) && (codeStream.pcToSourceMap[index][1] == oldPosition)) {
178
							codeStream.pcToSourceMap[index--][1] = position;
222
							codeStream.pcToSourceMap[index--][1] = position;

Return to bug 114855