-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
73179ac
to
d809afa
Compare
@ivovandongen everything is working as before, this PR is ready for a review |
d809afa
to
196a2a3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a loop like this, it's important to clean up the temporary local references (jni:DeleteLocalRef(jsonElement)
)
@@ -6,6 +6,20 @@ namespace mbgl { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ref?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete local references (jsonElement and key)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const ref
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete local reference
jni::jobject* converted = apply_visitor(jsonEvaluator, expressionValue); | ||
|
||
return converted; | ||
return gson::JsonElement::New(env, expressionValue);; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional ;
@@ -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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! will include this
@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.