Repository: flex-asjs Updated Branches: refs/heads/develop b24af71db -> 686bd3f3f
Added readByteAt() to enable optimized reading of BinaryData Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/686bd3f3 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/686bd3f3 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/686bd3f3 Branch: refs/heads/develop Commit: 686bd3f3ff7d351f37d8a66d668ddaaee1b443c6 Parents: b24af71 Author: Harbs <ha...@in-tools.com> Authored: Tue Jul 12 13:58:12 2016 +0300 Committer: Harbs <ha...@in-tools.com> Committed: Tue Jul 12 13:58:12 2016 +0300 ---------------------------------------------------------------------- .../flex/org/apache/flex/utils/BinaryData.as | 32 +++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/686bd3f3/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as index 573ada2..1e00af2 100644 --- a/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as +++ b/frameworks/projects/Core/src/main/flex/org/apache/flex/utils/BinaryData.as @@ -259,6 +259,33 @@ public class BinaryData return view[0]; } } + + /** + * Read a byte of binary data at the specified index. Does not change the <code>position</code> property. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function readByteAt(idx:uint):int + { + COMPILE::SWF + { + return ba[idx]; + } + COMPILE::JS + { + if(typedArray == null) + typedArray = new Uint8Array(ba); + return typedArray[idx]; + } + } + COMPILE::JS + { + private var typedArray:Uint8Array; + } + /** * Read a short int of binary data at the current position @@ -398,6 +425,7 @@ public class BinaryData var view:Uint8Array = new Uint8Array(ba, 0, Math.min(newSize,n)); newView.set(view); ba = newBuffer; + typedArray = null; } /** * The total number of bytes remaining to be read. @@ -491,6 +519,7 @@ public class BinaryData newView[i] = view[i]; } ba = newBuffer; + typedArray = null; } } } @@ -640,6 +669,7 @@ public class BinaryData var encoder:TextEncoder = new TextEncoder('utf-8'); bytes = encoder.encode(str); ba = bytes.buffer; + typedArray = null; return; } @@ -677,7 +707,7 @@ public class BinaryData } bytes = new Uint8Array(out); ba = bytes.buffer; - + typedArray = null; } } }