Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions core/common/src/internal/format/parser/ConcatenatedListView.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2019-2025 JetBrains s.r.o. and contributors.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

package kotlinx.datetime.internal.format.parser

internal class ConcatenatedListView<T>(val list1: List<T>, val list2: List<T>) : AbstractList<T>() {
override val size: Int
get() = list1.size + list2.size

override fun get(index: Int): T = if (index < list1.size) list1[index] else list2[index - list1.size]
}
2 changes: 1 addition & 1 deletion core/common/src/internal/format/parser/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class ParserStructure<in Output>(
// TODO: O(size of the resulting parser ^ 2), but can be O(size of the resulting parser)
internal fun <T> List<ParserStructure<T>>.concat(): ParserStructure<T> {
fun <T> ParserStructure<T>.append(other: ParserStructure<T>): ParserStructure<T> = if (followedBy.isEmpty()) {
ParserStructure(operations + other.operations, other.followedBy)
ParserStructure(ConcatenatedListView(operations, other.operations), other.followedBy)
} else {
ParserStructure(operations, followedBy.map { it.append(other) })
}
Expand Down