KT-9377 Support is-checks for read-only collections

Generate better code for 'as?' with mutable collection types:
use CHECKCAST, do not introduce special intrinsics for safe-as.
This commit is contained in:
Dmitry Petrov
2015-10-02 11:56:56 +03:00
parent e033d093d4
commit 06d9ff6a71
6 changed files with 46 additions and 125 deletions
@@ -51,20 +51,6 @@ public class TypeIntrinsics {
return result;
}
public static Iterator safeAsMutableIterator(Object obj) {
Iterator result;
try {
result = (Iterator) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterator)) {
return null;
}
return result;
}
public static boolean isMutableListIterator(Object obj) {
return (obj instanceof ListIterator) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableListIterator));
@@ -84,20 +70,6 @@ public class TypeIntrinsics {
return result;
}
public static ListIterator safeAsMutableListIterator(Object obj) {
ListIterator result;
try {
result = (ListIterator) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableListIterator)) {
return null;
}
return result;
}
public static boolean isMutableIterable(Object obj) {
return (obj instanceof Iterable) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableIterable));
@@ -117,20 +89,6 @@ public class TypeIntrinsics {
return result;
}
public static Iterable safeAsMutableIterable(Object obj) {
Iterable result;
try {
result = (Iterable) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableIterable)) {
return null;
}
return result;
}
public static boolean isMutableCollection(Object obj) {
return (obj instanceof Collection) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableCollection));
@@ -150,20 +108,6 @@ public class TypeIntrinsics {
return result;
}
public static Collection safeAsMutableCollection(Object obj) {
Collection result;
try {
result = (Collection) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableCollection)) {
return null;
}
return result;
}
public static boolean isMutableList(Object obj) {
return (obj instanceof List) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableList));
@@ -183,20 +127,6 @@ public class TypeIntrinsics {
return result;
}
public static List safeAsMutableList(Object obj) {
List result;
try {
result = (List) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableList)) {
return null;
}
return result;
}
public static boolean isMutableSet(Object obj) {
return (obj instanceof Set) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableSet));
@@ -216,20 +146,6 @@ public class TypeIntrinsics {
return result;
}
public static Set safeAsMutableSet(Object obj) {
Set result;
try {
result = (Set) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableSet)) {
return null;
}
return result;
}
public static boolean isMutableMap(Object obj) {
return (obj instanceof Map) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap));
@@ -249,20 +165,6 @@ public class TypeIntrinsics {
return result;
}
public static Map safeAsMutableMap(Object obj) {
Map result;
try {
result = (Map) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap)) {
return null;
}
return result;
}
public static boolean isMutableMapEntry(Object obj) {
return (obj instanceof Map.Entry) &&
(!(obj instanceof KMappedMarker) || (obj instanceof KMutableMap.Entry));
@@ -281,19 +183,4 @@ public class TypeIntrinsics {
}
return result;
}
public static Map.Entry safeAsMutableMapEntry(Object obj) {
Map.Entry result;
try {
result = (Map.Entry) obj;
}
catch (ClassCastException e) {
return null;
}
if ((obj instanceof KMappedMarker) && !(obj instanceof KMutableMap.Entry)) {
return null;
}
return result;
}
}