Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: libadblockplus-android/jni/Utils.cpp

Issue 29422558: Issue 5167 - Update to use libadblockplus revision dca8df9af1a7 (Closed)
Patch Set: updated dependencies (..-binaries) Created May 10, 2017, 6:54 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « libadblockplus-android/jni/Utils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: libadblockplus-android/jni/Utils.cpp
diff --git a/libadblockplus-android/jni/Utils.cpp b/libadblockplus-android/jni/Utils.cpp
index 282ae5b344ea6640f6a6de8c3daf89e6b8f87f13..02a2bade2e9fbadb7d1127b2441941c8cab6fb7c 100644
--- a/libadblockplus-android/jni/Utils.cpp
+++ b/libadblockplus-android/jni/Utils.cpp
@@ -164,37 +164,25 @@ JNIEnvAcquire::~JNIEnvAcquire()
}
template<typename T>
-static jobject NewJniObject(JNIEnv* env, const T& value, jclass clazz, jmethodID ctor)
+static jobject NewJniObject(JNIEnv* env, T&& value, jclass clazz, jmethodID ctor)
{
- if (!value.get())
- {
- return 0;
- }
-
- return env->NewObject(clazz, ctor, JniPtrToLong(new T(value)));
-}
-
-template<typename T>
-static jobject NewJniObject(JNIEnv* env, const T& value, const char* javaClass)
-{
- JniLocalReference<jclass> clazz( env, env->FindClass(javaClass));
- jmethodID ctor = env->GetMethodID(*clazz, "<init>", "(J)V");
- return NewJniObject(env, value, *clazz, ctor);
+ return env->NewObject(clazz, ctor, JniPtrToLong(new T(std::forward<T>(value))));
}
-jobject NewJniFilter(JNIEnv* env, const AdblockPlus::FilterPtr& filter)
+jobject NewJniFilter(JNIEnv* env, AdblockPlus::Filter&& filter)
{
- return NewJniObject(env, filter, filterClass->Get(), filterCtor);
+ return NewJniObject<AdblockPlus::Filter>(
+ env, std::move(filter), filterClass->Get(), filterCtor);
}
-jobject NewJniSubscription(JNIEnv* env,
- const AdblockPlus::SubscriptionPtr& subscription)
+jobject NewJniSubscription(JNIEnv* env, AdblockPlus::Subscription&& subscription)
{
- return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionCtor);
+ return NewJniObject<AdblockPlus::Subscription>(
+ env, std::move(subscription), subscriptionClass->Get(), subscriptionCtor);
}
-jobject NewJniNotification(JNIEnv* env,
- const AdblockPlus::NotificationPtr& notification)
+jobject NewJniNotification(JNIEnv* env, AdblockPlus::Notification&& notification)
{
- return NewJniObject(env, notification, notificationClass->Get(), notificationCtor);
+ return NewJniObject<AdblockPlus::Notification>(
+ env, std::move(notification), notificationClass->Get(), notificationCtor);
}
« no previous file with comments | « libadblockplus-android/jni/Utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld