Repository navigation
Rework expression conversion - #11490
Conversation
73179ac to
d809afa
Compare
|
@ivovandongen everything is working as before, this PR is ready for a review |
d809afa to
196a2a3
Compare
ivovandongen
left a comment
There was a problem hiding this comment.
Starting to look good!
|
|
||
| for (const auto &v : values) { | ||
| auto jsonElement = JsonElement::New(env, v); | ||
| jsonArray.Call(env, addMethod, jsonElement); |
There was a problem hiding this comment.
In a loop like this, it's important to clean up the temporary local references (jni:DeleteLocalRef(jsonElement))
| namespace android { | ||
| namespace gson { | ||
|
|
||
| jni::Object<JsonArray> JsonArray::New(jni::JNIEnv& env, std::vector<mapbox::geometry::value> values){ |
There was a problem hiding this comment.
You could pass the vector by const ref here.
|
|
||
| jni::JNIEnv& env; | ||
|
|
||
| jni::Object<JsonElement> operator()(const JsonPrimitive::value value) const { |
There was a problem hiding this comment.
Not seeing where I can add an additional const here
|
|
||
| for (auto &item : values) { | ||
| jni::Object<JsonElement> jsonElement = JsonElement::New(env, item.second); | ||
| jni::String key = jni::Make<jni::String>(env, item.first); |
There was a problem hiding this comment.
Delete local references (jsonElement and key)
| static auto constructor = JsonPrimitive::javaClass.GetConstructor<jni::Object<java::lang::Number>>(env); | ||
| auto boxedValue = java::lang::Double::valueOf(env, value); | ||
| auto number = jni::Cast(env, boxedValue, java::lang::Number::javaClass); | ||
| return JsonPrimitive::javaClass.New(env, constructor, number); |
There was a problem hiding this comment.
Delete local references
| */ | ||
| jni::Object<JsonPrimitive> operator()(const int64_t value) const { | ||
| static auto constructor = JsonPrimitive::javaClass.GetConstructor<jni::Object<java::lang::Number>>(env); | ||
| auto boxedValue = java::lang::Long::valueOf(env, value); |
There was a problem hiding this comment.
Delete local references
| jni::Object<JsonPrimitive> operator()(const uint64_t value) const { | ||
| // long conversion | ||
| static auto constructor = JsonPrimitive::javaClass.GetConstructor<jni::Object<java::lang::Number>>(env); | ||
| auto boxedValue = java::lang::Long::valueOf(env, value); |
There was a problem hiding this comment.
Delete local references
| */ | ||
| jni::Object<JsonPrimitive> operator()(const bool value) const { | ||
| static auto constructor = JsonPrimitive::javaClass.GetConstructor<jni::Object<java::lang::Boolean>>(env); | ||
| auto boxedValue = java::lang::Boolean::valueOf(env, value); |
There was a problem hiding this comment.
Delete local reference
| jni::jobject* converted = apply_visitor(jsonEvaluator, expressionValue); | ||
|
|
||
| return converted; | ||
| return gson::JsonElement::New(env, expressionValue);; |
| @@ -21,10 +22,7 @@ struct Converter<jni::jobject*, mbgl::style::CameraFunction<T>> { | |||
| Result<jni::jobject*> operator()(jni::JNIEnv& env, const mbgl::style::CameraFunction<T>& value) const { | |||
There was a problem hiding this comment.
If you want, you could one step further here and type the result with high-level types as well (jni::Object<...>), like https://github.com/mapbox/mapbox-gl-native/blob/release-boba/platform/android/src/geojson/conversion/geometry.hpp#L15
|
@ivovandongen I addressed your comments in a separate commit for ease of re-review. |
4d58709 to
222a2c0
Compare
81d3068 to
9a1c3f4
Compare
|
9a1c3f4 reworks passing by const reference instead of const value. |
Closes #11420 & #11419.