Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved processing related to parameter parsing on Kotlin #760

Merged
merged 5 commits into from Jan 20, 2024

Conversation

k163377
Copy link
Contributor

@k163377 k163377 commented Jan 20, 2024

The kotlinFunction has been changed so that it is not called directly, but is referred to in the cache.
This should improve the parsing speed at initialization.

Also, a common process for obtaining parameters on Kotlin was implemented, replacing the existing parameter obtaining process.

…existing

In addition, kotlinFunction calls were replaced with calls from the cache.
The hasRequiredMarker process had no problem without the check, so the findKotlinParameterName check process was removed.
Comment on lines -123 to -159
@Suppress("UNCHECKED_CAST")
private fun findKotlinParameterName(param: AnnotatedParameter): String? {
return if (param.declaringClass.isKotlinClass()) {
val member = param.owner.member
if (member is Constructor<*>) {
val ctor = (member as Constructor<Any>)
val ctorParmCount = ctor.parameterTypes.size
val ktorParmCount = try { ctor.kotlinFunction?.parameters?.size ?: 0 }
catch (ex: KotlinReflectionInternalError) { 0 }
catch (ex: UnsupportedOperationException) { 0 }
if (ktorParmCount > 0 && ktorParmCount == ctorParmCount) {
ctor.kotlinFunction?.parameters?.get(param.index)?.name
} else {
null
}
} else if (member is Method) {
try {
val temp = member.kotlinFunction

val firstParamKind = temp?.parameters?.firstOrNull()?.kind
val idx = if (firstParamKind != KParameter.Kind.VALUE) param.index + 1 else param.index
val parmCount = temp?.parameters?.size ?: 0
if (parmCount > idx) {
temp?.parameters?.get(idx)?.name
} else {
null
}
} catch (ex: KotlinReflectionInternalError) {
null
}
} else {
null
}
} else {
null
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the previous implementation of AnnotatedParameter.hasRequiredMarker in KotlinAnnotationIntrospector, parameter acquisition was called without a check.
In other words, these check processes are now considered meaningless and have been removed.
https://github.com/FasterXML/jackson-module-kotlin/pull/760/files#diff-938d5c566367fbca40b3ef96c99967dba4cd563f3854370272e0ae6b5d0f7f0d

@k163377 k163377 merged commit ea31521 into FasterXML:2.17 Jan 20, 2024
16 checks passed
@k163377 k163377 deleted the fix-conv-cache branch January 20, 2024 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant