Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of array add operation and type checker #43701

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -257,12 +257,15 @@ 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);
if (sourceType == targetType || (sourceType.getTag() == targetType.getTag() && sourceType.equals(targetType))) {
warunalakshitha marked this conversation as resolved.
Show resolved Hide resolved
return true;
}
if (isSubType(sourceType, targetType)) {
return true;
}
SemType sourceSemType = SemType.tryInto(sourceType);
Context cx = context();
return couldInherentTypeBeDifferent(sourceSemType) &&
isSubTypeWithInherentType(cx, sourceVal, SemType.tryInto(targetType));
}
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 @@ -662,27 +661,31 @@ public void setArrayRefTypeForcefully(ArrayType type, int size) {

public void addInt(long index, long value) {
if (intValues != null) {
prepareForAdd(index, value, intValues.length);
prepareForAddWithoutTypeCheck(index, intValues.length);
intValues[(int) index] = value;
return;
}

prepareForAdd(index, value, byteValues.length);
if (!TypeChecker.isByteLiteral(value)) {
throw ErrorCreator.createError(getModulePrefixedReason(ARRAY_LANG_LIB,
INHERENT_TYPE_VIOLATION_ERROR_IDENTIFIER), ErrorHelper.getErrorDetails(
ErrorCodes.INCOMPATIBLE_TYPE, this.elementType, TypeChecker.getType(value)));
}
prepareForAddWithoutTypeCheck(index, 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 +695,7 @@ private void addString(long index, String value) {
}

private void addBString(long index, BString value) {
prepareForAdd(index, value, bStringValues.length);
prepareForAddWithoutTypeCheck(index, bStringValues.length);
bStringValues[(int) index] = value;
}

Expand Down
Loading