From cb7738c2aa0e7d6c2b994aea1b8be33b02153b63 Mon Sep 17 00:00:00 2001 From: beliefer Date: Wed, 17 Dec 2025 19:47:48 +0800 Subject: [PATCH] [GLUTEN-11308][CORE] Avoid copy string for jStringToCString --- cpp/core/jni/JniCommon.h | 4 ++-- cpp/core/jni/JniWrapper.cc | 20 ++++++++++---------- cpp/velox/jni/VeloxJniWrapper.cc | 6 +++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cpp/core/jni/JniCommon.h b/cpp/core/jni/JniCommon.h index fdc084fd2f34..3a228cfd6c4e 100644 --- a/cpp/core/jni/JniCommon.h +++ b/cpp/core/jni/JniCommon.h @@ -32,7 +32,7 @@ static jint jniVersion = JNI_VERSION_1_8; -static inline std::string jStringToCString(JNIEnv* env, jstring string) { +static inline std::string jStringToCString(JNIEnv* env, const jstring& string) { if (!string) { return {}; } @@ -354,7 +354,7 @@ static inline arrow::Compression::type getCompressionType(JNIEnv* env, jstring c return compressionType; } -static inline gluten::CodecBackend getCodecBackend(JNIEnv* env, jstring codecBackendJstr) { +static inline gluten::CodecBackend getCodecBackend(JNIEnv* env, const jstring& codecBackendJstr) { if (codecBackendJstr == nullptr) { return gluten::CodecBackend::NONE; } diff --git a/cpp/core/jni/JniWrapper.cc b/cpp/core/jni/JniWrapper.cc index bfab41e3652a..20d813858097 100644 --- a/cpp/core/jni/JniWrapper.cc +++ b/cpp/core/jni/JniWrapper.cc @@ -309,7 +309,7 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) { JNIEXPORT jlong JNICALL Java_org_apache_gluten_runtime_RuntimeJniWrapper_createRuntime( // NOLINT JNIEnv* env, jclass, - jstring jBackendType, + const jstring& jBackendType, jlong nmmHandle, jbyteArray sessionConf) { JNI_METHOD_START @@ -341,7 +341,7 @@ const std::string kBacktraceAllocation = "spark.gluten.memory.backtrace.allocati JNIEXPORT jlong JNICALL Java_org_apache_gluten_memory_NativeMemoryManagerJniWrapper_create( // NOLINT JNIEnv* env, jclass, - jstring jBackendType, + const jstring& jBackendType, jobject jListener, jbyteArray sessionConf) { JNI_METHOD_START @@ -460,7 +460,7 @@ Java_org_apache_gluten_vectorized_PlanEvaluatorJniWrapper_nativeCreateKernelWith jint partitionId, jlong taskId, jboolean enableDumping, - jstring spillDir) { + const jstring& spillDir) { JNI_METHOD_START auto ctx = getRuntime(env, wrapper); @@ -857,8 +857,8 @@ Java_org_apache_gluten_vectorized_LocalPartitionWriterJniWrapper_createPartition jdouble mergeThreshold, jint numSubDirs, jint shuffleFileBufferSize, - jstring dataFileJstr, - jstring localDirsJstr, + const jstring& dataFileJstr, + const jstring& localDirsJstr, jboolean enableDictionary) { JNI_METHOD_START @@ -893,7 +893,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_ShuffleWriterJniWrappe JNIEnv* env, jobject wrapper, jint numPartitions, - jstring partitioningNameJstr, + const jstring& partitioningNameJstr, jint startPartitionId, jint splitBufferSize, jdouble splitBufferReallocThreshold, @@ -921,7 +921,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_ShuffleWriterJniWrappe JNIEnv* env, jobject wrapper, jint numPartitions, - jstring partitioningNameJstr, + const jstring& partitioningNameJstr, jint startPartitionId, jint splitBufferSize, jdouble splitBufferReallocThreshold, @@ -949,7 +949,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_ShuffleWriterJniWrappe JNIEnv* env, jobject wrapper, jint numPartitions, - jstring partitioningNameJstr, + const jstring& partitioningNameJstr, jint startPartitionId, jint diskWriteBufferSize, jint initialSortBufferSize, @@ -979,7 +979,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_ShuffleWriterJniWrappe JNIEnv* env, jobject wrapper, jint numPartitions, - jstring partitioningNameJstr, + const jstring& partitioningNameJstr, jint startPartitionId, jint splitBufferSize, jlong sortBufferMaxSize, @@ -1118,7 +1118,7 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_vectorized_ShuffleReaderJniWrappe jint batchSize, jlong readerBufferSize, jlong deserializerBufferSize, - jstring shuffleWriterType) { + const jstring& shuffleWriterType) { JNI_METHOD_START auto ctx = getRuntime(env, wrapper); diff --git a/cpp/velox/jni/VeloxJniWrapper.cc b/cpp/velox/jni/VeloxJniWrapper.cc index f44fed088822..64dc5ccb482d 100644 --- a/cpp/velox/jni/VeloxJniWrapper.cc +++ b/cpp/velox/jni/VeloxJniWrapper.cc @@ -482,7 +482,7 @@ Java_org_apache_gluten_utils_VeloxFileSystemValidationJniWrapper_allSupportedByR JNIEXPORT jlong JNICALL Java_org_apache_gluten_datasource_VeloxDataSourceJniWrapper_init( // NOLINT JNIEnv* env, jobject wrapper, - jstring filePath, + const jstring& filePath, jlong cSchema, jbyteArray options) { JNI_METHOD_START @@ -839,8 +839,8 @@ JNIEXPORT jlong JNICALL Java_org_apache_gluten_execution_IcebergWriteJniWrapper_ jobject wrapper, jlong cSchema, jint format, - jstring directory, - jstring codecJstr, + const jstring& directory, + const jstring& codecJstr, jbyteArray partition, jbyteArray fieldBytes) { JNI_METHOD_START