-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve arraybuffer performance (#126)
- Loading branch information
Showing
11 changed files
with
339 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverArrayEmu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.teavm.classlib.java.nio; | ||
|
||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.ArrayBufferViewWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.Float32ArrayWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.TypedArrays; | ||
import com.github.xpenatan.gdx.backends.teavm.gen.Emulate; | ||
|
||
@Emulate(valueStr = "java.nio.TFloatBufferOverArray", updateCode = true) | ||
public abstract class FloatBufferOverArrayEmu extends TFloatBufferOverArray implements HasArrayBufferView { | ||
|
||
@Emulate | ||
Float32ArrayWrapper backupArray; | ||
@Emulate | ||
int positionCache; | ||
@Emulate | ||
int remainingCache; | ||
|
||
public FloatBufferOverArrayEmu(int start, int capacity, float[] array, int position, int limit, boolean readOnly) { | ||
super(start, capacity, array, position, limit, readOnly); | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public ArrayBufferViewWrapper getArrayBufferView() { | ||
Float32ArrayWrapper originalBuffer = (Float32ArrayWrapper)getOriginalArrayBufferView(); | ||
int position1 = position(); | ||
int remaining1 = remaining(); | ||
if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { | ||
positionCache = position1; | ||
remainingCache = remaining1; | ||
backupArray = originalBuffer.subarray(position1, remaining1); | ||
} | ||
return backupArray; | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public ArrayBufferViewWrapper getOriginalArrayBufferView() { | ||
return TypedArrays.getTypedArray(array); | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public int getElementSize() { | ||
return 4; | ||
} | ||
} |
34 changes: 32 additions & 2 deletions
34
backends/backend-teavm/emu/org/teavm/classlib/java/nio/FloatBufferOverByteBufferEmu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
backends/backend-teavm/emu/org/teavm/classlib/java/nio/HasArrayBufferView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package org.teavm.classlib.java.nio; | ||
|
||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.Int8ArrayWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.ArrayBufferViewWrapper; | ||
|
||
public interface HasArrayBufferView { | ||
Int8ArrayWrapper getTypedArray(); | ||
ArrayBufferViewWrapper getArrayBufferView(); | ||
ArrayBufferViewWrapper getOriginalArrayBufferView(); | ||
int getElementSize(); | ||
} |
47 changes: 47 additions & 0 deletions
47
backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverArrayEmu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.teavm.classlib.java.nio; | ||
|
||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.ArrayBufferViewWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.Int32ArrayWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.TypedArrays; | ||
import com.github.xpenatan.gdx.backends.teavm.gen.Emulate; | ||
|
||
@Emulate(valueStr = "java.nio.TIntBufferOverArray", updateCode = true) | ||
public abstract class IntBufferOverArrayEmu extends TIntBufferOverArray implements HasArrayBufferView { | ||
|
||
@Emulate | ||
Int32ArrayWrapper backupArray; | ||
@Emulate | ||
int positionCache; | ||
@Emulate | ||
int remainingCache; | ||
|
||
public IntBufferOverArrayEmu(int start, int capacity, int[] array, int position, int limit, boolean readOnly) { | ||
super(start, capacity, array, position, limit, readOnly); | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public ArrayBufferViewWrapper getArrayBufferView() { | ||
Int32ArrayWrapper originalBuffer = (Int32ArrayWrapper)getOriginalArrayBufferView(); | ||
int position1 = position(); | ||
int remaining1 = remaining(); | ||
if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { | ||
positionCache = position1; | ||
remainingCache = remaining1; | ||
backupArray = originalBuffer.subarray(position1, remaining1); | ||
} | ||
return backupArray; | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public ArrayBufferViewWrapper getOriginalArrayBufferView() { | ||
return TypedArrays.getTypedArray(array); | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public int getElementSize() { | ||
return 4; | ||
} | ||
} |
35 changes: 33 additions & 2 deletions
35
backends/backend-teavm/emu/org/teavm/classlib/java/nio/IntBufferOverByteBufferEmu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverArrayEmu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.teavm.classlib.java.nio; | ||
|
||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.ArrayBufferViewWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.Int16ArrayWrapper; | ||
import com.github.xpenatan.gdx.backends.teavm.dom.typedarray.TypedArrays; | ||
import com.github.xpenatan.gdx.backends.teavm.gen.Emulate; | ||
|
||
@Emulate(valueStr = "java.nio.TShortBufferOverArray", updateCode = true) | ||
public abstract class ShortBufferOverArrayEmu extends TShortBufferOverArray implements HasArrayBufferView { | ||
|
||
@Emulate | ||
Int16ArrayWrapper backupArray; | ||
@Emulate | ||
int positionCache; | ||
@Emulate | ||
int remainingCache; | ||
|
||
public ShortBufferOverArrayEmu(int start, int capacity, short[] array, int position, int limit, boolean readOnly) { | ||
super(start, capacity, array, position, limit, readOnly); | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public ArrayBufferViewWrapper getArrayBufferView() { | ||
Int16ArrayWrapper originalBuffer = (Int16ArrayWrapper)getOriginalArrayBufferView(); | ||
int position1 = position(); | ||
int remaining1 = remaining(); | ||
if(backupArray == null || positionCache != position1 || remaining1 != remainingCache) { | ||
positionCache = position1; | ||
remainingCache = remaining1; | ||
backupArray = originalBuffer.subarray(position1, remaining1); | ||
} | ||
return backupArray; | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public ArrayBufferViewWrapper getOriginalArrayBufferView() { | ||
return TypedArrays.getTypedArray(array); | ||
} | ||
|
||
@Override | ||
@Emulate | ||
public int getElementSize() { | ||
return 2; | ||
} | ||
} |
34 changes: 32 additions & 2 deletions
34
backends/backend-teavm/emu/org/teavm/classlib/java/nio/ShortBufferOverByteBufferEmu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.