Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bcec82de authored by Ken Wakasa's avatar Ken Wakasa
Browse files

Clean up constructors

And, use C++ style casts and use float math functions rather than double ones to save memory space.

Also, stop using FloatMath and NativeUtils as standard Math methods are faster now.
See http://code.google.com/p/android/issues/detail?id=36199 and https://android-review.googlesource.com/40700

multi-project commit with I4259fb5ab8a15ac5760a7f04fc8f4c860529f04a

Change-Id: I0b81cff8c91769f7559a59b9528c75a5aabb4211
parent 81451030
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard;

import android.graphics.Rect;
import android.text.TextUtils;
import android.util.FloatMath;

import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection;
import com.android.inputmethod.latin.JniUtils;
@@ -155,7 +154,9 @@ public class ProximityInfo {
                    final float radius = touchPositionCorrection.mRadii[row];
                    sweetSpotCenterXs[i] = hitBox.exactCenterX() + x * hitBoxWidth;
                    sweetSpotCenterYs[i] = hitBox.exactCenterY() + y * hitBoxHeight;
                    sweetSpotRadii[i] = radius * FloatMath.sqrt(
                    // Note that, in recent versions of Android, FloatMath is actually slower than
                    // java.lang.Math due to the way the JIT optimizes java.lang.Math.
                    sweetSpotRadii[i] = radius * (float)Math.sqrt(
                            hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
                }
            }
+4 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ package com.android.inputmethod.keyboard.internal;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.FloatMath;

import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputPointers;
@@ -50,7 +49,7 @@ public class GestureStroke {
    private static final float GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec
    private static final float GESTURE_RECOG_CURVATURE_THRESHOLD = (float)(Math.PI / 4.0f);

    private static final float DOUBLE_PI = (float)(2 * Math.PI);
    private static final float DOUBLE_PI = (float)(2.0f * Math.PI);

    // Fade based on number of gesture samples, see MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT
    private static final int DRAWING_GESTURE_FADE_START = 10;
@@ -158,8 +157,9 @@ public class GestureStroke {
            final int p2x, final int p2y) {
        final float dx = p1x - p2x;
        final float dy = p1y - p2y;
        // TODO: Optimize out this {@link FloatMath#sqrt(float)} call.
        return FloatMath.sqrt(dx * dx + dy * dy);
        // Note that, in recent versions of Android, FloatMath is actually slower than
        // java.lang.Math due to the way the JIT optimizes java.lang.Math.
        return (float)Math.sqrt(dx * dx + dy * dy);
    }

    private static float getAngle(final int p1x, final int p1y, final int p2x, final int p2y) {
+0 −32
Original line number Diff line number Diff line
/*
 * Copyright (C) 2012 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.
 */

package com.android.inputmethod.latin;

public class NativeUtils {
    static {
        JniUtils.loadNativeLibrary();
    }

    private NativeUtils() {
        // This utility class is not publicly instantiable.
    }

    /**
     * This method just calls up libm's powf() directly.
     */
    public static native float powf(float x, float y);
}
+1 −1
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ public class UserHistoryForgettingCurveUtils {
                for (int j = 0; j < ELAPSED_TIME_MAX; ++j) {
                    final float elapsedHours = j * ELAPSED_TIME_INTERVAL_HOURS;
                    final float freq = initialFreq
                            * NativeUtils.powf(initialFreq, elapsedHours / HALF_LIFE_HOURS);
                            * (float)Math.pow(initialFreq, elapsedHours / HALF_LIFE_HOURS);
                    final int intFreq = Math.min(FC_FREQ_MAX, Math.max(0, (int)freq));
                    SCORE_TABLE[i][j] = intFreq;
                }
+0 −1
Original line number Diff line number Diff line
@@ -37,7 +37,6 @@ LATIN_IME_JNI_SRC_FILES := \
    com_android_inputmethod_keyboard_ProximityInfo.cpp \
    com_android_inputmethod_latin_BinaryDictionary.cpp \
    com_android_inputmethod_latin_DicTraverseSession.cpp \
    com_android_inputmethod_latin_NativeUtils.cpp \
    jni_common.cpp

LATIN_IME_CORE_SRC_FILES := \
Loading