Skip to content

Commit 131e6a6

Browse files
authored
Merge pull request #1123 from Kotlin/functions_inline_copy
Functions inline
2 parents a6e535e + cd181a6 commit 131e6a6

33 files changed

+378
-74
lines changed

core/api/core.api

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ public final class org/jetbrains/kotlinx/dataframe/api/AddDsl : org/jetbrains/ko
320320
public fun getColumnOrNull (Lkotlin/reflect/KProperty;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
321321
public fun getColumnOrNull (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
322322
public fun getColumnOrNull (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
323+
public final fun getColumns ()Ljava/util/List;
323324
public final fun getDf ()Lorg/jetbrains/kotlinx/dataframe/DataFrame;
324325
public final fun group (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
325326
public final fun group (Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/api/AddGroup;
@@ -598,8 +599,14 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/AllExceptCol
598599
public final class org/jetbrains/kotlinx/dataframe/api/AllKt {
599600
public static final fun all (Lorg/jetbrains/kotlinx/dataframe/DataColumn;Lkotlin/jvm/functions/Function1;)Z
600601
public static final fun all (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/jvm/functions/Function2;)Z
602+
public static final fun allAfterInternal (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;
603+
public static final fun allBeforeInternal (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;
604+
public static final fun allColumnsInternal (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Z)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet;
605+
public static synthetic fun allColumnsInternal$default (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;ZILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet;
606+
public static final fun allFromInternal (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;
601607
public static final fun allNA (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Z
602608
public static final fun allNulls (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Z
609+
public static final fun allUpToInternal (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;
603610
}
604611

605612
public abstract interface class org/jetbrains/kotlinx/dataframe/api/AndColumnsSelectionDsl {
@@ -1029,6 +1036,10 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColsInGroups
10291036
public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColsInGroupsColumnsSelectionDsl$Grammar$PlainDslName {
10301037
}
10311038

1039+
public final class org/jetbrains/kotlinx/dataframe/api/ColsKt {
1040+
public static final fun colsInternal (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet;
1041+
}
1042+
10321043
public abstract interface class org/jetbrains/kotlinx/dataframe/api/ColsOfColumnsSelectionDsl {
10331044
public fun colsOf (Ljava/lang/String;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;
10341045
public fun colsOf (Lkotlin/reflect/KProperty;Lkotlin/reflect/KType;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;
@@ -3898,6 +3909,8 @@ public final class org/jetbrains/kotlinx/dataframe/api/SortKt {
38983909
public final class org/jetbrains/kotlinx/dataframe/api/Split {
38993910
public fun <init> (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/jvm/functions/Function2;)V
39003911
public final fun cast ()Lorg/jetbrains/kotlinx/dataframe/api/Split;
3912+
public final fun getColumns ()Lkotlin/jvm/functions/Function2;
3913+
public final fun getDf ()Lorg/jetbrains/kotlinx/dataframe/DataFrame;
39013914
public fun toString ()Ljava/lang/String;
39023915
}
39033916

@@ -4862,6 +4875,10 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/columns/BaseColu
48624875
public abstract fun values ()Ljava/lang/Iterable;
48634876
}
48644877

4878+
public final class org/jetbrains/kotlinx/dataframe/columns/BaseColumnKt {
4879+
public static final fun getValues (Lorg/jetbrains/kotlinx/dataframe/columns/BaseColumn;)Ljava/lang/Iterable;
4880+
}
4881+
48654882
public abstract interface class org/jetbrains/kotlinx/dataframe/columns/ColumnAccessor : org/jetbrains/kotlinx/dataframe/columns/ColumnReference {
48664883
public abstract fun get (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnAccessor;
48674884
public fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnAccessor;
@@ -5573,6 +5590,14 @@ public final class org/jetbrains/kotlinx/dataframe/impl/api/ConvertToKt {
55735590
public static synthetic fun convertToImpl$default (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/reflect/KType;ZLorg/jetbrains/kotlinx/dataframe/api/ExcessiveColumns;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
55745591
}
55755592

5593+
public final class org/jetbrains/kotlinx/dataframe/impl/api/DuplicateKt {
5594+
public static final fun duplicateRowsImpl (Lorg/jetbrains/kotlinx/dataframe/DataFrame;ILjava/lang/Iterable;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
5595+
}
5596+
5597+
public final class org/jetbrains/kotlinx/dataframe/impl/api/GroupByKt {
5598+
public static final fun groupByImpl (Lorg/jetbrains/kotlinx/dataframe/DataFrame;ZLkotlin/jvm/functions/Function2;)Lorg/jetbrains/kotlinx/dataframe/api/GroupBy;
5599+
}
5600+
55765601
public final class org/jetbrains/kotlinx/dataframe/impl/api/InsertKt {
55775602
public static final fun insertImpl (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
55785603
}
@@ -5691,6 +5716,7 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/impl/columns/Tra
56915716

56925717
public final class org/jetbrains/kotlinx/dataframe/impl/columns/UtilsKt {
56935718
public static final fun asAnyFrameColumn (Lorg/jetbrains/kotlinx/dataframe/DataColumn;)Lorg/jetbrains/kotlinx/dataframe/columns/FrameColumn;
5719+
public static final fun transform (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/impl/columns/TransformableColumnSet;
56945720
}
56955721

56965722
public final class org/jetbrains/kotlinx/dataframe/impl/io/FastDoubleParser {

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataRowApi.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ internal interface DiffOrNullDocs
111111
*/
112112
@OptIn(ExperimentalTypeInference::class)
113113
@OverloadResolutionByLambdaReturnType
114-
public fun <T> DataRow<T>.diff(firstRowResult: Double, expression: RowExpression<T, Double>): Double =
114+
public inline fun <T> DataRow<T>.diff(firstRowResult: Double, expression: RowExpression<T, Double>): Double =
115115
prev()?.let { p -> expression(this, this) - expression(p, p) }
116116
?: firstRowResult
117117

@@ -121,21 +121,21 @@ public fun <T> DataRow<T>.diff(firstRowResult: Double, expression: RowExpression
121121
@OptIn(ExperimentalTypeInference::class)
122122
@OverloadResolutionByLambdaReturnType
123123
// required to resolve `diff(0) { intValue }`
124-
public fun <T> DataRow<T>.diff(firstRowResult: Int, expression: RowExpression<T, Int>): Int =
124+
public inline fun <T> DataRow<T>.diff(firstRowResult: Int, expression: RowExpression<T, Int>): Int =
125125
prev()?.let { p -> expression(this, this) - expression(p, p) }
126126
?: firstRowResult
127127

128128
/**
129129
* @include [DiffDocs]
130130
*/
131-
public fun <T> DataRow<T>.diff(firstRowResult: Long, expression: RowExpression<T, Long>): Long =
131+
public inline fun <T> DataRow<T>.diff(firstRowResult: Long, expression: RowExpression<T, Long>): Long =
132132
prev()?.let { p -> expression(this, this) - expression(p, p) }
133133
?: firstRowResult
134134

135135
/**
136136
* @include [DiffDocs]
137137
*/
138-
public fun <T> DataRow<T>.diff(firstRowResult: Float, expression: RowExpression<T, Float>): Float =
138+
public inline fun <T> DataRow<T>.diff(firstRowResult: Float, expression: RowExpression<T, Float>): Float =
139139
prev()?.let { p -> expression(this, this) - expression(p, p) }
140140
?: firstRowResult
141141

@@ -144,25 +144,25 @@ public fun <T> DataRow<T>.diff(firstRowResult: Float, expression: RowExpression<
144144
*/
145145
@OptIn(ExperimentalTypeInference::class)
146146
@OverloadResolutionByLambdaReturnType
147-
public fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Double>): Double? =
147+
public inline fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Double>): Double? =
148148
prev()?.let { p -> expression(this, this) - expression(p, p) }
149149

150150
/**
151151
* @include [DiffOrNullDocs]
152152
*/
153-
public fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Int>): Int? =
153+
public inline fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Int>): Int? =
154154
prev()?.let { p -> expression(this, this) - expression(p, p) }
155155

156156
/**
157157
* @include [DiffOrNullDocs]
158158
*/
159-
public fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Long>): Long? =
159+
public inline fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Long>): Long? =
160160
prev()?.let { p -> expression(this, this) - expression(p, p) }
161161

162162
/**
163163
* @include [DiffOrNullDocs]
164164
*/
165-
public fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Float>): Float? =
165+
public inline fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Float>): Float? =
166166
prev()?.let { p -> expression(this, this) - expression(p, p) }
167167

168168
public fun AnyRow.columnsCount(): Int = df().ncol
@@ -205,7 +205,7 @@ public fun <T> DataRow<T>.relative(relativeIndices: IntRange): DataFrame<T> =
205205
(relativeIndices.first + index).coerceIn(df().indices)..(relativeIndices.last + index).coerceIn(df().indices),
206206
)
207207

208-
public fun <T> DataRow<T>.movingAverage(k: Int, expression: RowExpression<T, Number>): Double {
208+
public inline fun <T> DataRow<T>.movingAverage(k: Int, expression: RowExpression<T, Number>): Double {
209209
var count = 0
210210
return backwardIterable().take(k).sumOf {
211211
count++

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ public class AddDsl<T>(
166166
ColumnSelectionDsl<T> {
167167

168168
// TODO: support adding column into path
169-
internal val columns = mutableListOf<AnyCol>()
169+
@PublishedApi
170+
internal val columns: MutableList<AnyCol> = mutableListOf<AnyCol>()
170171

171172
public fun add(column: AnyColumnReference): Boolean = columns.add(column.resolveSingle(df)!!.data)
172173

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/all.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public fun AnyRow.allNA(): Boolean = owner.columns().all { it[index()].isNA }
5252
// region DataFrame
5353

5454
/** Returns `true` if all [rows] match the given [predicate] or [rows] is empty. */
55-
public fun <T> DataFrame<T>.all(predicate: RowFilter<T>): Boolean = rows().all { predicate(it, it) }
55+
public inline fun <T> DataFrame<T>.all(predicate: RowFilter<T>): Boolean = rows().all { predicate(it, it) }
5656

5757
// endregion
5858

@@ -1204,6 +1204,7 @@ public interface AllColumnsSelectionDsl<out _UNUSED> {
12041204
* else it simply returns a [(transformable) ColumnSet][TransformableColumnSet] from [this]
12051205
* (like when [this] is a [ColumnSet]).
12061206
*/
1207+
@PublishedApi
12071208
internal fun ColumnsResolver<*>.allColumnsInternal(removePaths: Boolean = false): TransformableColumnSet<*> =
12081209
transform { cols ->
12091210
if (this is SingleColumn<*> && cols.singleOrNull()?.isColumnGroup() == true) {
@@ -1225,7 +1226,8 @@ internal fun ColumnsResolver<*>.allColumnsInternal(removePaths: Boolean = false)
12251226
* @param colByPredicate a function that takes a ColumnWithPath and returns true if the column matches the predicate, false otherwise
12261227
* @return a new ColumnSet containing all columns after the first column that matches the given predicate
12271228
*/
1228-
internal fun ColumnsResolver<*>.allAfterInternal(colByPredicate: ColumnFilter<*>): ColumnSet<*> {
1229+
@PublishedApi
1230+
internal inline fun ColumnsResolver<*>.allAfterInternal(crossinline colByPredicate: ColumnFilter<*>): ColumnSet<*> {
12291231
var take = false
12301232
return colsInternal {
12311233
if (take) {
@@ -1243,7 +1245,8 @@ internal fun ColumnsResolver<*>.allAfterInternal(colByPredicate: ColumnFilter<*>
12431245
* @param colByPredicate the predicate used to determine if a column should be included in the resulting set
12441246
* @return a column set containing all columns that satisfy the predicate
12451247
*/
1246-
internal fun ColumnsResolver<*>.allFromInternal(colByPredicate: ColumnFilter<*>): ColumnSet<*> {
1248+
@PublishedApi
1249+
internal inline fun ColumnsResolver<*>.allFromInternal(crossinline colByPredicate: ColumnFilter<*>): ColumnSet<*> {
12471250
var take = false
12481251
return colsInternal {
12491252
if (take) {
@@ -1261,7 +1264,8 @@ internal fun ColumnsResolver<*>.allFromInternal(colByPredicate: ColumnFilter<*>)
12611264
* @param colByPredicate the predicate function used to determine if a column should be included in the returned ColumnSet
12621265
* @return a new ColumnSet containing all columns that come before the first column that satisfies the given predicate
12631266
*/
1264-
internal fun ColumnsResolver<*>.allBeforeInternal(colByPredicate: ColumnFilter<*>): ColumnSet<*> {
1267+
@PublishedApi
1268+
internal inline fun ColumnsResolver<*>.allBeforeInternal(crossinline colByPredicate: ColumnFilter<*>): ColumnSet<*> {
12651269
var take = true
12661270
return colsInternal {
12671271
if (!take) {
@@ -1279,7 +1283,8 @@ internal fun ColumnsResolver<*>.allBeforeInternal(colByPredicate: ColumnFilter<*
12791283
* @param colByPredicate a predicate function that takes a ColumnWithPath and returns true if the column satisfies the desired condition.
12801284
* @return a ColumnSet containing all columns up to the first column that satisfies the given predicate.
12811285
*/
1282-
internal fun ColumnsResolver<*>.allUpToInternal(colByPredicate: ColumnFilter<*>): ColumnSet<*> {
1286+
@PublishedApi
1287+
internal inline fun ColumnsResolver<*>.allUpToInternal(crossinline colByPredicate: ColumnFilter<*>): ColumnSet<*> {
12831288
var take = true
12841289
return colsInternal {
12851290
if (!take) {

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/any.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ public fun <T> DataColumn<T>.any(predicate: Predicate<T>): Boolean = values.any(
1414

1515
// region DataFrame
1616

17-
public fun <T> DataFrame<T>.any(predicate: RowFilter<T>): Boolean = rows().any { predicate(it, it) }
17+
public inline fun <T> DataFrame<T>.any(predicate: RowFilter<T>): Boolean = rows().any { predicate(it, it) }
1818

1919
// endregion

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/associate.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import org.jetbrains.kotlinx.dataframe.RowExpression
66

77
// region DataFrame
88

9-
public fun <T, V> DataFrame<T>.associateBy(transform: RowExpression<T, V>): Map<V, DataRow<T>> =
9+
public inline fun <T, V> DataFrame<T>.associateBy(transform: RowExpression<T, V>): Map<V, DataRow<T>> =
1010
rows().associateBy { transform(it, it) }
1111

12-
public fun <T, K, V> DataFrame<T>.associate(transform: RowExpression<T, Pair<K, V>>): Map<K, V> =
12+
public inline fun <T, K, V> DataFrame<T>.associate(transform: RowExpression<T, Pair<K, V>>): Map<K, V> =
1313
rows().associate { transform(it, it) }
1414

1515
// endregion

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colGroups.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ public interface ColGroupsColumnsSelectionDsl {
178178
* @return A [TransformableColumnSet] containing the column groups that satisfy the filter.
179179
*/
180180
@Suppress("UNCHECKED_CAST")
181-
internal fun ColumnsResolver<*>.columnGroupsInternal(
182-
filter: (ColumnGroup<*>) -> Boolean,
181+
internal inline fun ColumnsResolver<*>.columnGroupsInternal(
182+
crossinline filter: (ColumnGroup<*>) -> Boolean,
183183
): TransformableColumnSet<AnyRow> = colsInternal { it.isColumnGroup() && filter(it) } as TransformableColumnSet<AnyRow>
184184

185185
// endregion

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cols.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,8 @@ internal fun SingleColumn<DataRow<*>>.colsInternal(refs: Iterable<ColumnReferenc
11081108
* Else, it returns a new [ColumnSet] containing all columns in this [ColumnsResolver] that
11091109
* match the given [predicate].
11101110
*/
1111-
internal fun ColumnsResolver<*>.colsInternal(predicate: ColumnFilter<*>): TransformableColumnSet<*> =
1111+
@PublishedApi
1112+
internal inline fun ColumnsResolver<*>.colsInternal(crossinline predicate: ColumnFilter<*>): TransformableColumnSet<*> =
11121113
allColumnsInternal().transform { it.filter(predicate) }
11131114

11141115
internal fun ColumnsResolver<*>.colsInternal(indices: IntArray): TransformableColumnSet<*> =

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsOf.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,10 @@ public inline fun <reified C> SingleColumn<DataRow<*>>.colsOf(
264264
* match the given [filter] and are the given [type].
265265
*/
266266
@Suppress("UNCHECKED_CAST")
267-
internal fun <C> ColumnsResolver<*>.colsOfInternal(type: KType, filter: ColumnFilter<C>): TransformableColumnSet<C> =
267+
internal inline fun <C> ColumnsResolver<*>.colsOfInternal(
268+
type: KType,
269+
crossinline filter: ColumnFilter<C>,
270+
): TransformableColumnSet<C> =
268271
colsInternal {
269272
it.isSubtypeOf(type) && filter(it.cast())
270273
} as TransformableColumnSet<C>

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/colsOfKind.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ public interface ColsOfKindColumnsSelectionDsl {
201201
* @param filter The filter function to apply on each column. Must accept a ColumnWithPath object and return a Boolean.
202202
* @return A [TransformableColumnSet] containing the columns of given kinds that satisfy the filter.
203203
*/
204-
internal fun ColumnsResolver<*>.columnsOfKindInternal(
204+
internal inline fun ColumnsResolver<*>.columnsOfKindInternal(
205205
kinds: Set<ColumnKind>,
206-
filter: ColumnFilter<*>,
206+
crossinline filter: ColumnFilter<*>,
207207
): TransformableColumnSet<*> = colsInternal { it.kind() in kinds && filter(it) }
208208

209209
// endregion

0 commit comments

Comments
 (0)