From e42c62c22e91ceba63ee2609abd04ca98d595820 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 14 Jan 2010 13:56:50 -0800 Subject: Speed up Character. Remove a useless layer of indirection in UCharacter (which is the bridge between java.lang.Character and ICU). We're not at the stage where the JIT can do this for us, and even if it could, why give it extra work to do? Also fix the incorrect copyright header which was probably copied from a file where it made sense. --- .../main/java/com/ibm/icu4jni/lang/UCharacter.java | 156 +++------------------ icu/src/main/native/CharacterInterface.c | 90 ++++++------ 2 files changed, 66 insertions(+), 180 deletions(-) (limited to 'icu/src/main') diff --git a/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java b/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java index 7ab1843..2839ac3 100644 --- a/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java +++ b/icu/src/main/java/com/ibm/icu4jni/lang/UCharacter.java @@ -20,141 +20,29 @@ import java.lang.Character.UnicodeBlock; public class UCharacter { - public static int digit(int codePoint, int radix) { - return digitImpl(codePoint, radix); - } - - private static native int digitImpl(int codePoint, int radix); - - public static int getType(int codePoint) { - return getTypeImpl(codePoint); - } - - private static native int getTypeImpl(int codePoint); - - public static byte getDirectionality(int codePoint) { - return getDirectionalityImpl(codePoint); - } - - private static native byte getDirectionalityImpl(int codePoint); - - public static boolean isMirrored(int codePoint) { - return isMirroredImpl(codePoint); - } - - private static native boolean isMirroredImpl(int codePoint); - - public static int getNumericValue(int codePoint) { - return getNumericValueImpl(codePoint); - } - - private static native int getNumericValueImpl(int codePoint); - - public static boolean isDefined(int codePoint) { - return isDefinedValueImpl(codePoint); - } - - private static native boolean isDefinedValueImpl(int codePoint); - - public static boolean isDigit(int codePoint) { - return isDigitImpl(codePoint); - } - - private static native boolean isDigitImpl(int codePoint); - - public static boolean isIdentifierIgnorable(int codePoint) { - return isIdentifierIgnorableImpl(codePoint); - } - - private static native boolean isIdentifierIgnorableImpl(int codePoint); - - public static boolean isLetter(int codePoint) { - return isLetterImpl(codePoint); - } - - private static native boolean isLetterImpl(int codePoint); - - public static boolean isLetterOrDigit(int codePoint) { - return isLetterOrDigitImpl(codePoint); - } - - private static native boolean isLetterOrDigitImpl(int codePoint); - - public static boolean isSpaceChar(int codePoint) { - return isSpaceCharImpl(codePoint); - } - - private static native boolean isSpaceCharImpl(int codePoint); - - public static boolean isTitleCase(int codePoint) { - return isTitleCaseImpl(codePoint); - } - - private static native boolean isTitleCaseImpl(int codePoint); - - public static boolean isUnicodeIdentifierPart(int codePoint) { - return isUnicodeIdentifierPartImpl(codePoint); - } - - private static native boolean isUnicodeIdentifierPartImpl(int codePoint); - - public static boolean isUnicodeIdentifierStart(int codePoint) { - return isUnicodeIdentifierStartImpl(codePoint); - } - - private static native boolean isUnicodeIdentifierStartImpl(int codePoint); - - public static boolean isWhitespace(int codePoint) { - return isWhitespaceImpl(codePoint); - } - - private static native boolean isWhitespaceImpl(int codePoint); - - public static int toLowerCase(int codePoint) { - return toLowerCaseImpl(codePoint); - } - - private static native int toLowerCaseImpl(int codePoint); - - public static int toTitleCase(int codePoint) { - return toTitleCaseImpl(codePoint); - } - - private static native int toTitleCaseImpl(int codePoint); - - public static int toUpperCase(int codePoint) { - return toUpperCaseImpl(codePoint); - } - - private static native int toUpperCaseImpl(int codePoint); - - public static boolean isUpperCase(int codePoint) { - return isUpperCaseImpl(codePoint); - } - - private static native boolean isUpperCaseImpl(int codePoint); - - public static boolean isLowerCase(int codePoint) { - return isLowerCaseImpl(codePoint); - } - - private static native boolean isLowerCaseImpl(int codePoint); - - public static int forName(String blockName) { - if (blockName == null) { - throw new NullPointerException(); - } - return forname(blockName); - } - - private static native int forname(String blockName); - - public static int of(int codePoint) { - return codeblock(codePoint); - } + public static native boolean isDefined(int codePoint); + public static native boolean isDigit(int codePoint); + public static native boolean isIdentifierIgnorable(int codePoint); + public static native boolean isLetter(int codePoint); + public static native boolean isLetterOrDigit(int codePoint); + public static native boolean isLowerCase(int codePoint); + public static native boolean isMirrored(int codePoint); + public static native boolean isSpaceChar(int codePoint); + public static native boolean isTitleCase(int codePoint); + public static native boolean isUnicodeIdentifierPart(int codePoint); + public static native boolean isUnicodeIdentifierStart(int codePoint); + public static native boolean isUpperCase(int codePoint); + public static native boolean isWhitespace(int codePoint); + public static native byte getDirectionality(int codePoint); + public static native int digit(int codePoint, int radix); + public static native int forName(String blockName); + public static native int getNumericValue(int codePoint); + public static native int getType(int codePoint); + public static native int of(int codePoint); + public static native int toLowerCase(int codePoint); + public static native int toTitleCase(int codePoint); + public static native int toUpperCase(int codePoint); - private static native int codeblock(int codePoint); - public static UnicodeBlock[] getBlockTable() { /** * The indices of the entries of this table correspond with the value diff --git a/icu/src/main/native/CharacterInterface.c b/icu/src/main/native/CharacterInterface.c index 70e9f29..26e6826 100644 --- a/icu/src/main/native/CharacterInterface.c +++ b/icu/src/main/native/CharacterInterface.c @@ -1,25 +1,23 @@ /* - * Copyright 2006 The Android Open Source Project - * - * Internal native functions. All of the functions defined here make - * direct use of VM functions or data structures, so they can't be written - * with JNI and shouldn't really be in a shared library. - * - * All functions here either complete quickly or are used to enter a wait - * state, so we don't set the thread status to THREAD_NATIVE when executing - * these methods. This means that the GC will wait for these functions - * to finish. DO NOT perform long operations or blocking I/O in here. - * - * In some cases we're following the division of labor defined by GNU - * ClassPath, e.g. java.lang.Thread has "Thread" and "VMThread", with - * the VM-specific behavior isolated in VMThread. + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "JNIHelp.h" #include "AndroidSystemNatives.h" #include "unicode/uchar.h" #include -#include static jint digitImpl(JNIEnv *env, jclass clazz, jint codePoint, jint radix) { return u_digit(codePoint, radix); @@ -69,7 +67,7 @@ static jint getNumericValueImpl(JNIEnv *env, jclass clazz, jint codePoint){ return result; } -static jboolean isDefinedValueImpl(JNIEnv *env, jclass clazz, jint codePoint) { +static jboolean isDefinedImpl(JNIEnv *env, jclass clazz, jint codePoint) { return u_isdefined(codePoint); } @@ -144,14 +142,18 @@ static jboolean isLowerCaseImpl(JNIEnv *env, jclass clazz, jint codePoint) { return u_islower(codePoint); } -static int forName(JNIEnv *env, jclass clazz, jstring blockName) { - const char *bName = (*env)->GetStringUTFChars(env, blockName, NULL); - int result = u_getPropertyValueEnum(UCHAR_BLOCK, bName); +static int forNameImpl(JNIEnv *env, jclass clazz, jstring blockName) { + if (blockName == NULL) { + jniThrowException(env, "java/lang/NullPointerException", NULL); + return -1; + } + const char* bName = (*env)->GetStringUTFChars(env, blockName, NULL); + int result = u_getPropertyValueEnum(UCHAR_BLOCK, bName); (*env)->ReleaseStringUTFChars(env, blockName, bName); return result; } -static int codeBlock(JNIEnv *env, jclass clazz, jint codePoint) { +static int ofImpl(JNIEnv *env, jclass clazz, jint codePoint) { return ublock_getCode(codePoint); } @@ -160,35 +162,31 @@ static int codeBlock(JNIEnv *env, jclass clazz, jint codePoint) { */ static JNINativeMethod gMethods[] = { /* name, signature, funcPtr */ - { "digitImpl", "(II)I", (void*) digitImpl }, - { "getTypeImpl", "(I)I", (void*) getTypeImpl }, - { "getDirectionalityImpl", "(I)B", (void*) getDirectionalityImpl }, - { "isMirroredImpl", "(I)Z", (void*) isMirroredImpl }, - { "getNumericValueImpl", "(I)I", (void*) getNumericValueImpl }, - { "isDefinedValueImpl", "(I)Z", (void*) isDefinedValueImpl }, - { "isDigitImpl", "(I)Z", (void*) isDigitImpl }, - { "isIdentifierIgnorableImpl", "(I)Z", (void*) isIdentifierIgnorableImpl }, - { "isLetterImpl", "(I)Z", (void*) isLetterImpl }, - { "isLetterOrDigitImpl", "(I)Z", (void*) isLetterOrDigitImpl }, - { "isSpaceCharImpl", "(I)Z", (void*) isSpaceCharImpl }, - { "isTitleCaseImpl", "(I)Z", (void*) isTitleCaseImpl }, - { "isUnicodeIdentifierPartImpl", "(I)Z", - (void*) isUnicodeIdentifierPartImpl }, - { "isUnicodeIdentifierStartImpl", "(I)Z", - (void*) isUnicodeIdentifierStartImpl }, - { "isWhitespaceImpl", "(I)Z", (void*) isWhitespaceImpl }, - { "toLowerCaseImpl", "(I)I", (void*) toLowerCaseImpl }, - { "toTitleCaseImpl", "(I)I", (void*) toTitleCaseImpl }, - { "toUpperCaseImpl", "(I)I", (void*) toUpperCaseImpl }, - { "isUpperCaseImpl", "(I)Z", (void*) isUpperCaseImpl }, - { "isLowerCaseImpl", "(I)Z", (void*) isLowerCaseImpl }, - { "forname", "(Ljava/lang/String;)I", (void*) forName }, - { "codeblock", "(I)I", (void*) codeBlock } + { "digit", "(II)I", (void*) digitImpl }, + { "forName", "(Ljava/lang/String;)I", (void*) forNameImpl }, + { "getDirectionality", "(I)B", (void*) getDirectionalityImpl }, + { "getNumericValue", "(I)I", (void*) getNumericValueImpl }, + { "getType", "(I)I", (void*) getTypeImpl }, + { "isDefined", "(I)Z", (void*) isDefinedImpl }, + { "isDigit", "(I)Z", (void*) isDigitImpl }, + { "isIdentifierIgnorable", "(I)Z", (void*) isIdentifierIgnorableImpl }, + { "isLetter", "(I)Z", (void*) isLetterImpl }, + { "isLetterOrDigit", "(I)Z", (void*) isLetterOrDigitImpl }, + { "isLowerCase", "(I)Z", (void*) isLowerCaseImpl }, + { "isMirrored", "(I)Z", (void*) isMirroredImpl }, + { "isSpaceChar", "(I)Z", (void*) isSpaceCharImpl }, + { "isTitleCase", "(I)Z", (void*) isTitleCaseImpl }, + { "isUnicodeIdentifierPart", "(I)Z", (void*) isUnicodeIdentifierPartImpl }, + { "isUnicodeIdentifierStart", "(I)Z", (void*) isUnicodeIdentifierStartImpl }, + { "isUpperCase", "(I)Z", (void*) isUpperCaseImpl }, + { "isWhitespace", "(I)Z", (void*) isWhitespaceImpl }, + { "of", "(I)I", (void*) ofImpl }, + { "toLowerCase", "(I)I", (void*) toLowerCaseImpl }, + { "toTitleCase", "(I)I", (void*) toTitleCaseImpl }, + { "toUpperCase", "(I)I", (void*) toUpperCaseImpl }, }; int register_com_ibm_icu4jni_lang_UCharacter(JNIEnv *env) { return jniRegisterNativeMethods(env, "com/ibm/icu4jni/lang/UCharacter", gMethods, NELEM(gMethods)); } - - -- cgit v1.1