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

Port to Kotlin Multiplatform #25

Merged
merged 105 commits into from
May 15, 2024
Merged

Port to Kotlin Multiplatform #25

merged 105 commits into from
May 15, 2024

Conversation

Ercalvez
Copy link
Contributor

Work still need to be done:

  • Publishing and signing setup

library-android has been moved to androidMain
FileSystem.SYSTEM is not available in commonMain.

# Conflicts:
#	library/src/main/java/de/westnordost/osmfeatures/CollectionUtils.kt
#	library/src/main/java/de/westnordost/osmfeatures/FeatureDictionnary.kt
#	library/src/main/java/de/westnordost/osmfeatures/StartsWithStringTree.kt
# Conflicts:
#	library/src/main/java/de/westnordost/osmfeatures/ContainedMapTree.kt
# Conflicts:
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/BaseFeature.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/CollectionUtils.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/ContainedMapTree.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/Feature.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/FeatureDictionnary.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/FeatureTagsIndex.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/FeatureTermIndex.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/FileAccessAdapter.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/FileSystemAccess.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/GeometryType.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDBrandPresetsFeatureCollection.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDLocalizedFeatureCollection.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDPresetsJsonParser.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/IDPresetsTranslationJsonParser.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/JsonUtils.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/Locale.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/LocalizedFeature.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/LocalizedFeatureCollection.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/PerCountryFeatureCollection.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/StartsWithStringTree.kt
#	library/src/commonMain/kotlin/de.westnordost.osmfeatures/StringUtils.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/CollectionUtilsTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/FeatureDictionaryTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/FeatureTagsIndexTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/FeatureTermIndexTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDBrandPresetsFeatureCollectionTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDLocalizedFeatureCollectionTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDPresetsJsonParserTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/IDPresetsTranslationJsonParserTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/JsonUtilsTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/LivePresetDataAccessAdapter.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/StartsWithStringTreeTest.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/TestLocalizedFeatureCollection.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/TestPerCountryFeatureCollection.kt
#	library/src/commonTest/kotlin/de.westnordost.osmfeatures/TestUtils.kt
Copy link
Owner

@westnordost westnordost left a comment

Choose a reason for hiding this comment

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

A very incomplete review while in the train. I think when home I'll rather check out the branch and correct all the small issues I find myself and only note the bigger ones (if any) here on github, more efficient that way.

It's a good idea to have the Android-specific stuff in the Android-part of the library itself, makes sense.

Four general comments:

  1. The directory name looks suspect: library/src/commonMain/kotlin/de.westnordost.osmfeatures/... - i.e. why are there dots in the name instead of subdirectories? It's the first time that I see this. I checked the Kotlin coding conventions and didn't see that mentioned.

  2. Regarding the build.gradle.kts: I recently created another kotlin multiplatform library, maybe you could copy it from there: https://github.com/westnordost/osm-opening-hours

  3. Some fields, parameters and variables you made nullable even though this looks like an oversight. In case it is not, comments should be added to the source to explain / document it.

  4. With kotlinx-serialization-json it is not necessary (nor recommended, as far as I know) to do JSON parsing by hand. You can simply annotate the data model how it should be (de)serialized. See https://kotlinlang.org/docs/serialization.html#serialize-and-deserialize-json . Did you not know this, or is there some reason why you chose to parse it by hand?

@westnordost westnordost merged commit b51f189 into westnordost:master May 15, 2024
@westnordost
Copy link
Owner

Alright, merged. In the end, the line of code count is only 72% of what we had for Java. 🎉

Since we made breaking changes to the API anyway (Locale -> String), I also changed a few more things that were bothering me.

For the time being, the initialization of the multiplatform version is about 15% slower than before. I think this is mainly due to whole file read into a string first, then into a DOM and then only in the final data structure. At least the first step should be solvable once kotlinx-serialization-json supports directly reading kotlinx.io.Source.

@Ercalvez
Copy link
Contributor Author

Alright, merged. In the end, the line of code count is only 72% of what we had for Java. 🎉

Since we made breaking changes to the API anyway (Locale -> String), I also changed a few more things that were bothering me.

For the time being, the initialization of the multiplatform version is about 15% slower than before. I think this is mainly due to whole file read into a string first, then into a DOM and then only in the final data structure. At least the first step should be solvable once kotlinx-serialization-json supports directly reading kotlinx.io.Source.

Wow, 72% reduction is impressive 🎉

@westnordost
Copy link
Owner

Nono, reduction TO 72%

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.

3 participants