diff options
author | Yigit Boyar <yboyar@google.com> | 2017-12-28 17:13:44 -0800 |
---|---|---|
committer | Yigit Boyar <yboyar@google.com> | 2018-01-09 16:55:38 +0000 |
commit | c56acaa6c114d8a4a463b97f6b02b6a1d508f152 (patch) | |
tree | b4f07f1291578c6bae1a6eddc6a668c09301d765 /compiler/src/main/kotlin/android/databinding | |
parent | 28efa96610b913ce5b30cc36ed33dbf1b62f3f66 (diff) | |
download | data-binding-c56acaa6c114d8a4a463b97f6b02b6a1d508f152.tar.gz |
Detect common null check ternary ops
This CL adds logic to the Ternary expression to avoid unboxing
if the predicate is a null check.
e.g. if it is a == null ? b : a, we don't need to unbox for the
false statement because it will not be executed if a is null.
This is not a complete nullability detection code, it only covers the
common cases.
Bug: 37127560
Test: SafeUnboxingTest
Change-Id: I7a090b7dc92f1c127cc3b63f7eab3f6c37a250a8
Diffstat (limited to 'compiler/src/main/kotlin/android/databinding')
-rw-r--r-- | compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt index 52cf109f..6659cd53 100644 --- a/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt +++ b/compiler/src/main/kotlin/android/databinding/tool/writer/LayoutBinderWriter.kt @@ -1156,7 +1156,7 @@ class LayoutBinderWriter(val layoutBinder : LayoutBinder) { it.isMandatory && it.other.resolvedType.isNullable }.map { it.other } if (!expr.isEqualityCheck && nullables.isNotEmpty()) { - return "${nullables.map { "${it.executePendingLocalName} != null" }.joinToString(" && ")}" + return nullables.map { "${it.executePendingLocalName} != null" }.joinToString(" && ") } else { return null } |