Skip to content

Commit a5c6d43

Browse files
committed
Cleanup code used for advanced matching
1 parent 2eb0f01 commit a5c6d43

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

class-match/src/main/java/datadog/instrument/classmatch/FieldOutline.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public final class FieldOutline {
2626
this.descriptor = descriptor;
2727
}
2828

29+
// ----------------------------------------------------------------------------------------------
30+
// The rest of this class is used to implement advanced matching, while keeping outlines minimal
31+
// ----------------------------------------------------------------------------------------------
32+
2933
/** Lazy cache of the field's type-string hash. */
3034
private int typeStringHash;
3135

class-match/src/main/java/datadog/instrument/classmatch/MethodOutline.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ public final class MethodOutline {
3131
this.annotations = annotations;
3232
}
3333

34+
// ----------------------------------------------------------------------------------------------
35+
// The rest of this class is used to implement advanced matching, while keeping outlines minimal
36+
// ----------------------------------------------------------------------------------------------
37+
38+
private static final int[] NO_BOUNDARIES = {};
39+
40+
/** Lazy cache of boundaries between each parameter/return descriptor. */
41+
private int[] descriptorBoundaries;
42+
43+
/** Lazy cache of hashes for each parameter/return type-string. */
44+
private int[] typeStringHashes;
45+
3446
/**
3547
* @return number of method parameters
3648
*/
@@ -77,10 +89,18 @@ TypeString returnTypeString() {
7789
return new TypeString(descriptor, start, end, getHash(returnIndex, start, end));
7890
}
7991

80-
private static final int[] NO_BOUNDARIES = {};
81-
82-
/** Lazy cache of boundaries between each parameter/return descriptor. */
83-
private int[] descriptorBoundaries;
92+
/** Gets a previously cached {@link TypeString} hash; otherwise computes and caches a new hash. */
93+
private int getHash(int typeStringIndex, int start, int end) {
94+
if (typeStringHashes == null) {
95+
// allow for one hash per parameter, plus one for return type
96+
typeStringHashes = new int[descriptorBoundaries.length + 1];
97+
}
98+
int hash = typeStringHashes[typeStringIndex];
99+
if (hash == 0) {
100+
typeStringHashes[typeStringIndex] = hash = TypeString.computeHash(descriptor, start, end);
101+
}
102+
return hash;
103+
}
84104

85105
/**
86106
* Returns the boundaries between each parameter/return descriptor in the method descriptor.
@@ -138,20 +158,4 @@ private static int[] parseBoundaries(String descriptor) {
138158
}
139159
return boundaries;
140160
}
141-
142-
/** Lazy cache of hashes for each parameter/return type-string. */
143-
private int[] typeStringHashes;
144-
145-
/** Gets a previously cached {@link TypeString} hash; otherwise computes and caches a new hash. */
146-
private int getHash(int typeStringIndex, int start, int end) {
147-
if (typeStringHashes == null) {
148-
// allow for one hash per parameter, plus one for return type
149-
typeStringHashes = new int[descriptorBoundaries.length + 1];
150-
}
151-
int hash = typeStringHashes[typeStringIndex];
152-
if (hash == 0) {
153-
typeStringHashes[typeStringIndex] = hash = TypeString.computeHash(descriptor, start, end);
154-
}
155-
return hash;
156-
}
157161
}

0 commit comments

Comments
 (0)