Remove ICU usage from jni_helpers.cc.

JNI already has jstring<->UTF8 string conversion, so using that should
save ~1mb off android binaries (ICU is *large*), probably around
300-400k after compression.

BUG=

Review URL: https://codereview.webrtc.org/1430023005

Cr-Commit-Position: refs/heads/master@{#10545}
This commit is contained in:
noahric 2015-11-06 13:56:06 -08:00 committed by Commit bot
parent a821afec8a
commit 23725e09c6
7 changed files with 16 additions and 43 deletions

View File

@ -1,4 +1,3 @@
/*
* libjingle
* Copyright 2015 Google Inc.
@ -33,8 +32,6 @@
#include <sys/syscall.h>
#include <unistd.h>
#include "unicode/unistr.h"
namespace webrtc_jni {
static JavaVM* g_jvm = nullptr;
@ -46,8 +43,6 @@ static pthread_once_t g_jni_ptr_once = PTHREAD_ONCE_INIT;
// were attached by the JVM because of a Java->native call.
static pthread_key_t g_jni_ptr;
using icu::UnicodeString;
JavaVM *GetJVM() {
RTC_CHECK(g_jvm) << "JNI_OnLoad failed to run?";
return g_jvm;
@ -232,22 +227,20 @@ bool IsNull(JNIEnv* jni, jobject obj) {
// Given a UTF-8 encoded |native| string return a new (UTF-16) jstring.
jstring JavaStringFromStdString(JNIEnv* jni, const std::string& native) {
UnicodeString ustr(UnicodeString::fromUTF8(native));
jstring jstr = jni->NewString(ustr.getBuffer(), ustr.length());
CHECK_EXCEPTION(jni) << "error during NewString";
jstring jstr = jni->NewStringUTF(native.c_str());
CHECK_EXCEPTION(jni) << "error during NewStringUTF";
return jstr;
}
// Given a (UTF-16) jstring return a new UTF-8 native string.
std::string JavaToStdString(JNIEnv* jni, const jstring& j_string) {
const jchar* jchars = jni->GetStringChars(j_string, NULL);
CHECK_EXCEPTION(jni) << "Error during GetStringChars";
UnicodeString ustr(jchars, jni->GetStringLength(j_string));
CHECK_EXCEPTION(jni) << "Error during GetStringLength";
jni->ReleaseStringChars(j_string, jchars);
CHECK_EXCEPTION(jni) << "Error during ReleaseStringChars";
std::string ret;
return ustr.toUTF8String(ret);
const char* chars = jni->GetStringUTFChars(j_string, NULL);
CHECK_EXCEPTION(jni) << "Error during GetStringUTFChars";
std::string str(chars, jni->GetStringUTFLength(j_string));
CHECK_EXCEPTION(jni) << "Error during GetStringUTFLength";
jni->ReleaseStringUTFChars(j_string, chars);
CHECK_EXCEPTION(jni) << "Error during ReleaseStringUTFChars";
return str;
}
// Return the (singleton) Java Enum object corresponding to |index|;

View File

@ -41,7 +41,6 @@
],
# Disable these to not build components which can be externally provided.
'build_expat%': 1,
'build_icu%': 1,
'build_json%': 1,
'build_libsrtp%': 1,
'build_libyuv%': 1,

View File

@ -62,11 +62,6 @@
'<(libyuv_dir)/include',
],
'conditions': [
['build_icu==1', {
'dependencies': [
'<(DEPTH)/third_party/icu/icu.gyp:icuuc',
],
}],
['OS=="linux"', {
'defines': [
'HAVE_GTK',

View File

@ -89,7 +89,6 @@
# Disable these to not build components which can be externally provided.
'build_expat%': 1,
'build_icu%': 1,
'build_json%': 1,
'build_libjpeg%': 1,
'build_libvpx%': 1,

View File

@ -36,7 +36,6 @@ declare_args() {
# Disable these to not build components which can be externally provided.
rtc_build_expat = true
rtc_build_icu = true
rtc_build_json = true
rtc_build_libjpeg = true
rtc_build_libvpx = true

View File

@ -12,10 +12,6 @@
#include <limits>
#include "unicode/unistr.h"
using icu::UnicodeString;
jmethodID GetMethodID(JNIEnv* jni, jclass c, const std::string& name,
const char* signature) {
jmethodID m = jni->GetMethodID(c, name.c_str(), signature);
@ -36,14 +32,13 @@ jlong jlongFromPointer(void* ptr) {
// Given a (UTF-16) jstring return a new UTF-8 native string.
std::string JavaToStdString(JNIEnv* jni, const jstring& j_string) {
const jchar* jchars = jni->GetStringChars(j_string, NULL);
CHECK_JNI_EXCEPTION(jni, "Error during GetStringChars");
UnicodeString ustr(jchars, jni->GetStringLength(j_string));
CHECK_JNI_EXCEPTION(jni, "Error during GetStringLength");
jni->ReleaseStringChars(j_string, jchars);
CHECK_JNI_EXCEPTION(jni, "Error during ReleaseStringChars");
std::string ret;
return ustr.toUTF8String(ret);
const char* chars = jni->GetStringUTFChars(j_string, NULL);
CHECK_JNI_EXCEPTION(jni, "Error during GetStringUTFChars");
std::string str(chars, jni->GetStringUTFLength(j_string));
CHECK_JNI_EXCEPTION(jni, "Error during GetStringUTFLength");
jni->ReleaseStringUTFChars(j_string, chars);
CHECK_JNI_EXCEPTION(jni, "Error during ReleaseStringUTFChars");
return str;
}
ClassReferenceHolder::ClassReferenceHolder(JNIEnv* jni, const char** classes,

View File

@ -26,13 +26,6 @@
'examples/android/media_demo/jni/on_load.cc',
'examples/android/media_demo/jni/voice_engine_jni.cc',
],
'conditions': [
['build_icu==1', {
'dependencies': [
'<(DEPTH)/third_party/icu/icu.gyp:icuuc',
],
}],
],
'variables': {
# This library uses native JNI exports; tell GYP so that the
# required symbols will be kept.