Remove nGetWidths and pass the jfloat[] as nComputeLineBreaks argument.
nGetWidths was always called just before nComputeLineBreaks. It would be
an improvement to pass the result array as the argument of
nComputeLineBreaks.
Bug: 65024629
Test: bit FrameworksCoreTests:android.text.StaticLayoutLineBreakingTest
Test: bit CtsTextTestCase:*
Test: Manually checked no regression in TextViewOnMeasurePerfTest
Test: Manually checked no regression in StaticLayoutPerfTest result
Change-Id: I566be66558a22b3a3ff79d502bebbbfec75dd065
diff --git a/core/jni/android_text_StaticLayout.cpp b/core/jni/android_text_StaticLayout.cpp
index 83ffeff..1f7277a 100644
--- a/core/jni/android_text_StaticLayout.cpp
+++ b/core/jni/android_text_StaticLayout.cpp
@@ -166,7 +166,7 @@
jobject recycle, jintArray recycleBreaks,
jfloatArray recycleWidths, jfloatArray recycleAscents,
jfloatArray recycleDescents, jintArray recycleFlags,
- jint recycleLength) {
+ jint recycleLength, jfloatArray charWidths) {
minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
size_t nBreaks = b->computeBreaks();
@@ -175,6 +175,8 @@
recycleFlags, recycleLength, nBreaks, b->getBreaks(), b->getWidths(), b->getAscents(),
b->getDescents(), b->getFlags());
+ env->SetFloatArrayRegion(charWidths, 0, b->size(), b->charWidths());
+
b->finish();
return static_cast<jint>(nBreaks);
@@ -256,11 +258,6 @@
b->addReplacement(start, end, width, langTagsString.get(), makeHyphenators(env, hyphenators));
}
-static void nGetWidths(JNIEnv* env, jclass, jlong nativePtr, jfloatArray widths) {
- minikin::LineBreaker* b = reinterpret_cast<minikin::LineBreaker*>(nativePtr);
- env->SetFloatArrayRegion(widths, 0, b->size(), b->charWidths());
-}
-
static const JNINativeMethod gMethods[] = {
// TODO performance: many of these are candidates for fast jni, awaiting guidance
{"nNewBuilder", "()J", (void*) nNewBuilder},
@@ -269,8 +266,7 @@
{"nSetupParagraph", "(J[CIFIF[IIIIZ[I[I[II)V", (void*) nSetupParagraph},
{"nAddStyleRun", "(JJIIZLjava/lang/String;[J)V", (void*) nAddStyleRun},
{"nAddReplacementRun", "(JIIFLjava/lang/String;[J)V", (void*) nAddReplacementRun},
- {"nGetWidths", "(J[F)V", (void*) nGetWidths},
- {"nComputeLineBreaks", "(JLandroid/text/StaticLayout$LineBreaks;[I[F[F[F[II)I",
+ {"nComputeLineBreaks", "(JLandroid/text/StaticLayout$LineBreaks;[I[F[F[F[II[F)I",
(void*) nComputeLineBreaks}
};