mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-05 22:30:29 +00:00
Slightly improve performance by changing JNI method calls to field retrievals
This commit is contained in:
parent
cb0fe0f772
commit
e0067df491
2 changed files with 26 additions and 35 deletions
|
|
@ -2118,8 +2118,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
private boolean dirty;
|
||||
private final String id;
|
||||
private final String mimeType;
|
||||
private long lastModified;
|
||||
private long size;
|
||||
public final boolean isDirectory;
|
||||
public long lastModified;
|
||||
public long size;
|
||||
private final Uri uri;
|
||||
private final Uri tree;
|
||||
private HashMap <String, SAFDocument> children;
|
||||
|
|
@ -2129,6 +2130,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
this.mimeType = cursor.getString(2);
|
||||
this.lastModified = cursor.getLong(3);
|
||||
this.size = cursor.getLong(4);
|
||||
this.isDirectory = this.mimeType.equals(DocumentsContract.Document.MIME_TYPE_DIR);
|
||||
this.tree = uri;
|
||||
this.uri = uri;
|
||||
this.dirty = false;
|
||||
|
|
@ -2141,12 +2143,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
this.size = cursor.getLong(4);
|
||||
this.tree = parent.tree;
|
||||
this.uri = DocumentsContract.buildDocumentUriUsingTree(this.tree, this.id);
|
||||
this.isDirectory = this.mimeType.equals(DocumentsContract.Document.MIME_TYPE_DIR);
|
||||
this.dirty = false;
|
||||
}
|
||||
|
||||
private SAFDocument(Uri tree) {
|
||||
this.id = DocumentsContract.getTreeDocumentId(tree);
|
||||
this.mimeType = DocumentsContract.Document.MIME_TYPE_DIR;
|
||||
this.isDirectory = true;
|
||||
this.tree = tree;
|
||||
this.uri = DocumentsContract.buildDocumentUriUsingTree(this.tree, this.id);
|
||||
this.dirty = true;
|
||||
|
|
@ -2156,6 +2160,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
{
|
||||
this.id = DocumentsContract.getDocumentId(uri);
|
||||
this.mimeType = mimeType;
|
||||
this.isDirectory = this.mimeType.equals(DocumentsContract.Document.MIME_TYPE_DIR);
|
||||
this.lastModified = System.currentTimeMillis();
|
||||
this.tree = tree;
|
||||
this.uri = uri;
|
||||
|
|
@ -2221,6 +2226,10 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
}
|
||||
}
|
||||
|
||||
if (document.dirty) {
|
||||
document.update();
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
|
|
@ -2264,8 +2273,8 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
return newFileInfo;
|
||||
}
|
||||
|
||||
public HashMap <String, SAFDocument> getChildren() throws FileNotFoundException {
|
||||
if (!this.isDirectory()) {
|
||||
private HashMap <String, SAFDocument> getChildren() throws FileNotFoundException {
|
||||
if (!this.isDirectory) {
|
||||
throw new FileNotFoundException(this.id + " is not a directory for uri: " + this.uri);
|
||||
}
|
||||
if (this.children != null) {
|
||||
|
|
@ -2313,24 +2322,6 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
|||
this.dirty = false;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return this.mimeType.equals(DocumentsContract.Document.MIME_TYPE_DIR);
|
||||
}
|
||||
|
||||
public long getLastModified() {
|
||||
if (this.dirty) {
|
||||
this.update();
|
||||
}
|
||||
return this.lastModified;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
if (this.dirty) {
|
||||
this.update();
|
||||
}
|
||||
return this.size;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return this.uri.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -438,9 +438,9 @@ static jobject javaAssetManagerRef = 0;
|
|||
|
||||
// Android content file handling
|
||||
static jclass mSAFDocumentClass = NULL;
|
||||
static jmethodID midIsDirectory = NULL;
|
||||
static jmethodID midGetLastModified = NULL;
|
||||
static jmethodID midGetSize = NULL;
|
||||
static jfieldID fidIsDirectory = NULL;
|
||||
static jfieldID fidLastModified = NULL;
|
||||
static jfieldID fidSize = NULL;
|
||||
static jmethodID midGetUri = NULL;
|
||||
|
||||
static SDL_Mutex *Android_ActivityMutex = NULL;
|
||||
|
|
@ -2591,7 +2591,7 @@ static char *GetURIWithNormalizedPath(const char *uri, bool should_append_slash)
|
|||
|
||||
static bool CreateSAFDocumentClass(JNIEnv *env, jobject jSAFDocument)
|
||||
{
|
||||
if (mSAFDocumentClass && midIsDirectory && midGetLastModified && midGetSize && midGetUri) {
|
||||
if (mSAFDocumentClass && fidIsDirectory && fidLastModified && fidSize && midGetUri) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2613,22 +2613,22 @@ static bool CreateSAFDocumentClass(JNIEnv *env, jobject jSAFDocument)
|
|||
}
|
||||
}
|
||||
|
||||
if (!midIsDirectory) {
|
||||
midIsDirectory = (*env)->GetMethodID(env, mSAFDocumentClass, "isDirectory", "()Z");
|
||||
if (!fidIsDirectory) {
|
||||
fidIsDirectory = (*env)->GetFieldID(env, mSAFDocumentClass, "isDirectory", "Z");
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!midGetLastModified) {
|
||||
midGetLastModified = (*env)->GetMethodID(env, mSAFDocumentClass, "getLastModified", "()J");
|
||||
if (!fidLastModified) {
|
||||
fidLastModified = (*env)->GetFieldID(env, mSAFDocumentClass, "lastModified", "J");
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!midGetSize) {
|
||||
midGetSize = (*env)->GetMethodID(env, mSAFDocumentClass, "getSize", "()J");
|
||||
if (!fidSize) {
|
||||
fidSize = (*env)->GetFieldID(env, mSAFDocumentClass, "size", "J");
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -2817,19 +2817,19 @@ bool Android_JNI_GetContentInfo(const char *uri, SDL_PathInfo *info)
|
|||
}
|
||||
|
||||
// Get the fields from the SAFDocument object
|
||||
bool is_directory = (*env)->CallBooleanMethod(env, jSAFDocument, midIsDirectory);
|
||||
bool is_directory = (*env)->GetBooleanField(env, jSAFDocument, fidIsDirectory);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return false;
|
||||
}
|
||||
|
||||
long last_modified = (*env)->CallLongMethod(env, jSAFDocument, midGetLastModified);
|
||||
jlong last_modified = (*env)->GetLongField(env, jSAFDocument, fidLastModified);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return false;
|
||||
}
|
||||
|
||||
long size = (*env)->CallLongMethod(env, jSAFDocument, midGetSize);
|
||||
jlong size = (*env)->GetLongField(env, jSAFDocument, fidSize);
|
||||
if (Android_JNI_ExceptionOccurred(false)) {
|
||||
LocalReferenceHolder_Cleanup(&refs);
|
||||
return false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue