Skip to content

Commit

Permalink
Faster next() and upgrade NDK/CMake
Browse files Browse the repository at this point in the history
next() now uses SetFloatArrayRegion to avoid JNI allocations.
  • Loading branch information
romainguy committed Sep 7, 2022
1 parent a67b5de commit f4888a0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GROUP=dev.romainguy
VERSION_NAME=0.6.0
VERSION_NAME=0.7.0

SONATYPE_HOST=S01
RELEASE_SIGNING_ENABLED=true
Expand Down
8 changes: 4 additions & 4 deletions pathway/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ group = GROUP
version = VERSION_NAME

android {
compileSdk 31
ndkVersion '23.1.7779620'
compileSdk 33
ndkVersion '25.0.8775105'

defaultConfig {
minSdk 21
targetSdk 31
targetSdk 33

externalNativeBuild {
cmake {
Expand All @@ -36,7 +36,7 @@ android {
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.18.1'
version '3.22.1'
}
}
}
Expand Down
27 changes: 2 additions & 25 deletions pathway/src/main/cpp/pathway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,31 +111,8 @@ static jint pathIteratorNext(
Verb verb = pathIterator->next(pointsData);

if (verb != Verb::Done && verb != Verb::Close) {
auto* pointsArray = static_cast<jfloat*>(env->GetPrimitiveArrayCritical(points_, nullptr));
jfloat* points = pointsArray + offset_;
switch (verb) {
case Verb::Cubic:
case Verb::Conic: // to copy the weight
points[6] = pointsData[3].x;
points[7] = pointsData[3].y;
case Verb::Quadratic:
points[4] = pointsData[2].x;
points[5] = pointsData[2].y;
case Verb::Move:
case Verb::Line:
points[2] = pointsData[1].x;
points[3] = pointsData[1].y;
points[0] = pointsData[0].x;
points[1] = pointsData[0].y;
break;
#pragma clang diagnostic push
#pragma ide diagnostic ignored "UnreachableCode"
case Verb::Close:
case Verb::Done:
break;
#pragma clang diagnostic pop
}
env->ReleasePrimitiveArrayCritical(points_, pointsArray, 0);
auto* floatsData = reinterpret_cast<jfloat*>(pointsData);
env->SetFloatArrayRegion(points_, offset_, 8, floatsData);
}

return static_cast<jint>(verb);
Expand Down

0 comments on commit f4888a0

Please sign in to comment.