Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Rework expression conversion - #11490

Merged
tobrun merged 3 commits into
release-bobafrom
tvn-rework-expression-conversion
Apr 10, 2018
Merged

tobrun merged 3 commits into
release-bobafrom
tvn-rework-expression-conversion

Conversation

@tobrun

@tobrun tobrun commented Mar 21, 2018 •

Copy link
Copy Markdown
Member

Closes #11420 & #11419.

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Mar 21, 2018
@tobrun tobrun added this to the android-v6.0.0 milestone Mar 21, 2018
@tobrun tobrun self-assigned this Mar 21, 2018
@tobrun
tobrun force-pushed the tvn-rework-expression-conversion branch 2 times, most recently from 73179ac to d809afa Compare March 23, 2018 17:53
@tobrun
tobrun requested a review from ivovandongen March 23, 2018 17:56
@tobrun

tobrun commented Mar 23, 2018

Copy link
Copy Markdown
Member Author

@ivovandongen everything is working as before, this PR is ready for a review

@tobrun
tobrun force-pushed the tvn-rework-expression-conversion branch from d809afa to 196a2a3 Compare March 24, 2018 21:21

@ivovandongen ivovandongen left a comment

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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))

namespace android {
namespace gson {

jni::Object<JsonArray> JsonArray::New(jni::JNIEnv& env, std::vector<mapbox::geometry::value> values){

Copy link
Copy Markdown
Contributor

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const ref?

Copy link
Copy Markdown
Member Author

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);

Copy link
Copy Markdown
Contributor

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)

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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);;

Copy link
Copy Markdown
Contributor

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 {

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nice! will include this

@tobrun

tobrun commented Apr 5, 2018

Copy link
Copy Markdown
Member Author

@ivovandongen I addressed your comments in a separate commit for ease of re-review.
Thanks for 👀'in, ready for re-review.

@tobrun
tobrun force-pushed the tvn-rework-expression-conversion branch from 4d58709 to 222a2c0 Compare April 5, 2018 20:36
@tobrun
tobrun force-pushed the tvn-rework-expression-conversion branch from 81d3068 to 9a1c3f4 Compare April 9, 2018 18:39
@tobrun

tobrun commented Apr 10, 2018 •

Copy link
Copy Markdown
Member Author

9a1c3f4 reworks passing by const reference instead of const value.

@tobrun
tobrun merged commit 44ce5ab into release-boba Apr 10, 2018
@tobrun
tobrun deleted the tvn-rework-expression-conversion branch April 10, 2018 09:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Android Mapbox Maps SDK for Android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants