Skip to content

Commit

Permalink
Merge pull request #43701 from warunalakshitha/perf_fix_semtype
Browse files Browse the repository at this point in the history
Improve performance of array add  operation and type checker
  • Loading branch information
warunalakshitha authored Dec 19, 2024
2 parents 109f6cc + e01fe53 commit fbb3a35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public TypeCheckCache(T owner) {
}

public Optional<Boolean> cachedTypeCheckResult(T other) {
if (other.equals(owner)) {
return Optional.of(true);
}
return Optional.ofNullable(cachedResults.get(other));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@ public static boolean anyToJBoolean(Object sourceVal) {
* @return true if the value belongs to the given type, false otherwise
*/
public static boolean checkIsType(Object sourceVal, Type targetType) {
Context cx = context();
Type sourceType = getType(sourceVal);
Context cx = context();
if (isSubType(cx, sourceType, targetType)) {
return true;
}
Expand Down Expand Up @@ -605,6 +605,9 @@ private static boolean isSubTypeWithInherentType(Context cx, Object sourceValue,
}

private static boolean isSubType(Context cx, Type source, Type target) {
if (source == target || (source.getTag() == target.getTag() && source.equals(target))) {
return true;
}
if (source instanceof CacheableTypeDescriptor sourceCacheableType &&
target instanceof CacheableTypeDescriptor targetCacheableType) {
return isSubTypeWithCache(cx, sourceCacheableType, targetCacheableType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,6 @@ public void convertStringAndAddRefValue(long index, Object value) {
}

public void addRefValue(long index, Object value) {
Type type = TypeChecker.getType(value);
switch (this.elementReferredType.getTag()) {
case TypeTags.BOOLEAN_TAG:
prepareForAdd(index, value, booleanValues.length);
Expand Down Expand Up @@ -661,28 +660,36 @@ public void setArrayRefTypeForcefully(ArrayType type, int size) {
}

public void addInt(long index, long value) {
Type sourceType = TypeChecker.getType(value);
if (intValues != null) {
prepareForAdd(index, value, intValues.length);
if (sourceType == this.elementType) {
prepareForAddWithoutTypeCheck(index, intValues.length);
} else {
prepareForAdd(index, value, intValues.length);
}
intValues[(int) index] = value;
return;
}

prepareForAdd(index, value, byteValues.length);
if (sourceType == this.elementType) {
prepareForAddWithoutTypeCheck(index, byteValues.length);
} else {
prepareForAdd(index, value, byteValues.length);
}
byteValues[(int) index] = (byte) ((Long) value).intValue();
}

private void addBoolean(long index, boolean value) {
prepareForAdd(index, value, booleanValues.length);
prepareForAddWithoutTypeCheck(index, booleanValues.length);
booleanValues[(int) index] = value;
}

private void addByte(long index, byte value) {
prepareForAdd(index, value, byteValues.length);
prepareForAddWithoutTypeCheck(index, byteValues.length);
byteValues[(int) index] = value;
}

private void addFloat(long index, double value) {
prepareForAdd(index, value, floatValues.length);
prepareForAddWithoutTypeCheck(index, floatValues.length);
floatValues[(int) index] = value;
}

Expand All @@ -692,7 +699,12 @@ private void addString(long index, String value) {
}

private void addBString(long index, BString value) {
prepareForAdd(index, value, bStringValues.length);
Type sourceType = TypeChecker.getType(value);
if (sourceType == this.elementType) {
prepareForAddWithoutTypeCheck(index, bStringValues.length);
} else {
prepareForAdd(index, value, bStringValues.length);
}
bStringValues[(int) index] = value;
}

Expand Down

0 comments on commit fbb3a35

Please sign in to comment.