From 80e8183757a629c2f6419667deba23aedc4e7850 Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Mon, 22 Apr 2019 22:05:27 +0430 Subject: [PATCH] Use more idiomatic and implicit pointer dereference --- DroidFishApp/src/main/cpp/gtb/GtbProbe.cpp | 36 +++++++++++----------- DroidFishApp/src/main/cpp/nativeutil.cpp | 4 +-- DroidFishApp/src/main/cpp/rtb/RtbProbe.cpp | 16 +++++----- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/DroidFishApp/src/main/cpp/gtb/GtbProbe.cpp b/DroidFishApp/src/main/cpp/gtb/GtbProbe.cpp index 2f968eb..fdb79fd 100644 --- a/DroidFishApp/src/main/cpp/gtb/GtbProbe.cpp +++ b/DroidFishApp/src/main/cpp/gtb/GtbProbe.cpp @@ -31,7 +31,7 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_init( JNIEnv* env, jclass cls, jstring jTbPath) { initOk = false; - const char* tbPath = (*env).GetStringUTFChars(jTbPath, NULL); + const char* tbPath = env->GetStringUTFChars(jTbPath, NULL); if (!tbPath) return false; @@ -39,12 +39,12 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_init( tbpaths_done(paths); paths = tbpaths_init(); if (paths == NULL) { - (*env).ReleaseStringUTFChars(jTbPath, tbPath); + env->ReleaseStringUTFChars(jTbPath, tbPath); return false; } paths = tbpaths_add(paths, tbPath); if (paths == NULL) { - (*env).ReleaseStringUTFChars(jTbPath, tbPath); + env->ReleaseStringUTFChars(jTbPath, tbPath); return false; } @@ -61,7 +61,7 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_init( } isInitialized = true; - (*env).ReleaseStringUTFChars(jTbPath, tbPath); + env->ReleaseStringUTFChars(jTbPath, tbPath); initOk = true; return true; } @@ -79,7 +79,7 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_probeHard( { if (!initOk) return false; - if ((*env).GetArrayLength(result) < 2) + if (env->GetArrayLength(result) < 2) return false; const int MAXLEN = 17; @@ -88,29 +88,29 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_probeHard( unsigned char bp[MAXLEN]; unsigned int bs[MAXLEN]; - int len = (*env).GetArrayLength(whiteSquares); - jint* jiPtr = (*env).GetIntArrayElements(whiteSquares, NULL); + int len = env->GetArrayLength(whiteSquares); + jint* jiPtr = env->GetIntArrayElements(whiteSquares, NULL); for (int i = 0; i < min(len, MAXLEN); i++) ws[i] = jiPtr[i]; - (*env).ReleaseIntArrayElements(whiteSquares, jiPtr, 0); + env->ReleaseIntArrayElements(whiteSquares, jiPtr, 0); - len = (*env).GetArrayLength(blackSquares); - jiPtr = (*env).GetIntArrayElements(blackSquares, NULL); + len = env->GetArrayLength(blackSquares); + jiPtr = env->GetIntArrayElements(blackSquares, NULL); for (int i = 0; i < min(len, MAXLEN); i++) bs[i] = jiPtr[i]; - (*env).ReleaseIntArrayElements(blackSquares, jiPtr, 0); + env->ReleaseIntArrayElements(blackSquares, jiPtr, 0); - len = (*env).GetArrayLength(whitePieces); - jbyte* jcPtr = (*env).GetByteArrayElements(whitePieces, NULL); + len = env->GetArrayLength(whitePieces); + jbyte* jcPtr = env->GetByteArrayElements(whitePieces, NULL); for (int i = 0; i < min(len, MAXLEN); i++) wp[i] = jcPtr[i]; - (*env).ReleaseByteArrayElements(whitePieces, jcPtr, 0); + env->ReleaseByteArrayElements(whitePieces, jcPtr, 0); - len = (*env).GetArrayLength(blackPieces); - jcPtr = (*env).GetByteArrayElements(blackPieces, NULL); + len = env->GetArrayLength(blackPieces); + jcPtr = env->GetByteArrayElements(blackPieces, NULL); for (int i = 0; i < min(len, MAXLEN); i++) bp[i] = jcPtr[i]; - (*env).ReleaseByteArrayElements(blackPieces, jcPtr, 0); + env->ReleaseByteArrayElements(blackPieces, jcPtr, 0); unsigned int tbInfo; unsigned int plies; @@ -125,6 +125,6 @@ JNICALL Java_org_petero_droidfish_tb_GtbProbe_probeHard( res[0] = tbInfo; res[1] = plies; - (*env).SetIntArrayRegion(result, 0, 2, res); + env->SetIntArrayRegion(result, 0, 2, res); return ret != 0; } diff --git a/DroidFishApp/src/main/cpp/nativeutil.cpp b/DroidFishApp/src/main/cpp/nativeutil.cpp index de93aa2..02d967d 100644 --- a/DroidFishApp/src/main/cpp/nativeutil.cpp +++ b/DroidFishApp/src/main/cpp/nativeutil.cpp @@ -30,11 +30,11 @@ */ extern "C" JNIEXPORT jboolean JNICALL Java_org_petero_droidfish_engine_EngineUtil_chmod (JNIEnv *env, jclass, jstring jExePath) { - const char* exePath = (*env).GetStringUTFChars(jExePath, NULL); + const char* exePath = env->GetStringUTFChars(jExePath, NULL); if (!exePath) return false; bool ret = chmod(exePath, 0744) == 0; - (*env).ReleaseStringUTFChars(jExePath, exePath); + env->ReleaseStringUTFChars(jExePath, exePath); return ret; } diff --git a/DroidFishApp/src/main/cpp/rtb/RtbProbe.cpp b/DroidFishApp/src/main/cpp/rtb/RtbProbe.cpp index 32312f3..7f2f84d 100644 --- a/DroidFishApp/src/main/cpp/rtb/RtbProbe.cpp +++ b/DroidFishApp/src/main/cpp/rtb/RtbProbe.cpp @@ -27,11 +27,11 @@ JNICALL Java_org_petero_droidfish_tb_RtbProbe_init( JNIEnv* env, jclass cls, jstring jTbPath) { initOk = false; - const char* tbPath = (*env).GetStringUTFChars(jTbPath, NULL); + const char* tbPath = env->GetStringUTFChars(jTbPath, NULL); if (!tbPath) return false; std::string rtbPath(tbPath); - (*env).ReleaseStringUTFChars(jTbPath, tbPath); + env->ReleaseStringUTFChars(jTbPath, tbPath); TBProbe::initialize(rtbPath); initOk = true; @@ -45,26 +45,26 @@ JNICALL Java_org_petero_droidfish_tb_RtbProbe_probe( jint halfMoveClock, jint fullMoveCounter, jintArray result) { - if ((*env).GetArrayLength(result) < 2) + if (env->GetArrayLength(result) < 2) return; jint res[2]; res[0] = 1000; res[1] = 1000; - (*env).SetIntArrayRegion(result, 0, 2, res); + env->SetIntArrayRegion(result, 0, 2, res); if (!initOk) return; - const int len = (*env).GetArrayLength(jSquares); + const int len = env->GetArrayLength(jSquares); if (len != 64) return; Position pos; - jbyte* jbPtr = (*env).GetByteArrayElements(jSquares, NULL); + jbyte* jbPtr = env->GetByteArrayElements(jSquares, NULL); for (int i = 0; i < 64; i++) pos.setPiece(i, jbPtr[i]); - (*env).ReleaseByteArrayElements(jSquares, jbPtr, 0); + env->ReleaseByteArrayElements(jSquares, jbPtr, 0); pos.setWhiteMove(wtm); pos.setEpSquare(epSq); @@ -78,5 +78,5 @@ JNICALL Java_org_petero_droidfish_tb_RtbProbe_probe( if (TBProbe::rtbProbeDTZ(pos, score)) res[1] = score; - (*env).SetIntArrayRegion(result, 0, 2, res); + env->SetIntArrayRegion(result, 0, 2, res); }