This repository was archived by the owner on Jan 20, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
src/main/kotlin/com/mapk/fastkfunction/argumentbucket Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -16,9 +16,12 @@ class ArgumentBucket(
16
16
17
17
operator fun set (key : KParameter , value : Any? ): Any? = set(key.index, value)
18
18
19
- operator fun set (index : Int , value : Any? ): Any? = valueArray[index].apply {
20
- if (this == = ABSENT_VALUE ) count++
19
+ operator fun set (index : Int , value : Any? ): Any? = if (isInitialized(index))
20
+ valueArray[index].apply { valueArray[index] = value }
21
+ else {
22
+ count++
21
23
valueArray[index] = value
24
+ null // 値がABSENT_VALUEならnullを返す
22
25
}
23
26
24
27
/* *
@@ -31,11 +34,12 @@ class ArgumentBucket(
31
34
* If the specified key is not already associated with a value associates it with the given value and returns
32
35
* {@code null}, else returns the current value.
33
36
*/
34
- fun setIfAbsent (index : Int , value : Any? ): Any? = valueArray[index].apply {
35
- if (this == = ABSENT_VALUE ) {
36
- count++
37
- valueArray[index] = value
38
- }
37
+ fun setIfAbsent (index : Int , value : Any? ): Any? = if (isInitialized(index))
38
+ valueArray[index]
39
+ else {
40
+ count++
41
+ valueArray[index] = value
42
+ null // 値がABSENT_VALUEならnullを返す
39
43
}
40
44
41
45
private fun isInitialized (index : Int ): Boolean = valueArray[index] != = ABSENT_VALUE
You can’t perform that action at this time.
0 commit comments