mirror of
https://github.com/fumiama/android-base16384.git
synced 2026-06-05 18:20:32 +08:00
v3.1
1. 不使用压缩时字符串在内存直接编解码 2. 减少读取配置次数
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include <jni.h>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include "base16384.h"
|
||||
#include <cstring>
|
||||
#include "base16384.hpp"
|
||||
|
||||
#define execute(function){\
|
||||
const char *inputFileDir = env->GetStringUTFChars(sf, JNI_FALSE);\
|
||||
@@ -12,11 +13,26 @@
|
||||
return re;\
|
||||
}
|
||||
|
||||
extern "C" int encode_file(const char* input, const char* output);
|
||||
extern "C" int decode_file(const char* input, const char* output);
|
||||
#define exe_byte(fun) {\
|
||||
uint32_t len = env->GetArrayLength(buf);\
|
||||
const uint8_t* data = (uint8_t*)env->GetByteArrayElements(buf, JNI_FALSE);\
|
||||
LENDAT* ld = fun(data, len);\
|
||||
jbyteArray out = env->NewByteArray(ld->len);\
|
||||
auto out_data = env->GetByteArrayElements(out, JNI_FALSE);\
|
||||
memcpy(out_data, ld->data, ld->len);\
|
||||
free(ld);\
|
||||
env->ReleaseByteArrayElements(out, out_data, JNI_COMMIT);\
|
||||
return out;\
|
||||
}
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_encode(JNIEnv* env, jobject, jstring sf, jstring df) execute(encode_file)
|
||||
|
||||
extern "C" JNIEXPORT int JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file)
|
||||
Java_top_fumiama_base16384_MainActivity_decode(JNIEnv* env, jobject, jstring sf, jstring df) execute(decode_file)
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_encodeByteArray(JNIEnv* env, jobject, jbyteArray buf) exe_byte(encode)
|
||||
|
||||
extern "C" JNIEXPORT jbyteArray JNICALL
|
||||
Java_top_fumiama_base16384_MainActivity_decodeByteArray(JNIEnv* env, jobject, jbyteArray buf) exe_byte(decode)
|
||||
Reference in New Issue
Block a user