Small refactoring to use Family.CodeExtension.size when appropriate
This commit is contained in:
@@ -292,7 +292,7 @@ object Elements : TemplateGroupBase() {
|
||||
on(Platform.JS) {
|
||||
inline(Inline.No)
|
||||
|
||||
val size = if (f == CharSequences) "length" else "size"
|
||||
val size = f.code.size
|
||||
body {
|
||||
"""
|
||||
return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, $size: $$size}") }
|
||||
@@ -944,11 +944,10 @@ object Elements : TemplateGroupBase() {
|
||||
}
|
||||
specialFor(ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned, CharSequences) {
|
||||
body {
|
||||
val size = if (family == CharSequences) "length" else "size"
|
||||
"""
|
||||
if (isEmpty())
|
||||
throw NoSuchElementException("${f.doc.collection.capitalize()} is empty.")
|
||||
return get(random.nextInt($size))
|
||||
return get(random.nextInt(${f.code.size}))
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -966,7 +966,7 @@ object Generators : TemplateGroupBase() {
|
||||
}
|
||||
body(CharSequences) {
|
||||
"""
|
||||
val size = ${if (f == CharSequences) "length" else "size" } - 1
|
||||
val size = ${f.code.size} - 1
|
||||
if (size < 1) return emptyList()
|
||||
val result = ArrayList<R>(size)
|
||||
for (index in 0 until size) {
|
||||
|
||||
@@ -162,7 +162,7 @@ object Snapshots : TemplateGroupBase() {
|
||||
}
|
||||
body(CharSequences, ArraysOfPrimitives, ArraysOfObjects) {
|
||||
"""
|
||||
return when (${ if (f == CharSequences) "length" else "size" }) {
|
||||
return when (${f.code.size}) {
|
||||
0 -> emptyList()
|
||||
1 -> listOf(this[0])
|
||||
else -> this.toMutableList()
|
||||
|
||||
Reference in New Issue
Block a user