royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [royale-asjs] branch develop updated: Use single instance of DataView
Date Mon, 25 Jun 2018 08:15:15 GMT
This is an automated email from the ASF dual-hosted git repository.

harbs pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new d778e8b  Use single instance of DataView
d778e8b is described below

commit d778e8b482b6f6b0798cf566b1745d3087a89cde
Author: Harbs <harbs@in-tools.com>
AuthorDate: Mon Jun 25 11:15:07 2018 +0300

    Use single instance of DataView
    
    This should have a significant performance improvement
---
 .../royale/org/apache/royale/utils/BinaryData.as    | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
index aa13003..4deb23e 100644
--- a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
+++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/BinaryData.as
@@ -417,7 +417,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
                 setBufferSize(_position + 4);
             }
             
-            new DataView(ba).setFloat32(_position,val,_endian == Endian.LITTLE_ENDIAN);
+            getDataView().setFloat32(_position,val,_endian == Endian.LITTLE_ENDIAN);
             _position += 4;
         }
     }
@@ -441,7 +441,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             if (_position + 8 > _len) {
                 setBufferSize(_position + 8);
             }
-            new DataView(ba).setFloat64(_position,val,_endian == Endian.LITTLE_ENDIAN);
+            getDataView().setFloat64(_position,val,_endian == Endian.LITTLE_ENDIAN);
             _position += 8;
         }
     }
@@ -587,6 +587,17 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
         return _typedArray;
     }
 
+    COMPILE::JS
+    private var _dataView:DataView;
+
+    COMPILE::JS
+    private function getDataView():DataView
+    {
+        if(!_dataView)
+            _dataView = new DataView(ba);
+        return _dataView;
+    }
+
 
     /**
      *  Writes a byte of binary data at the specified index. Does not change the <code>position</code>
property.
@@ -726,7 +737,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             return ba.readFloat();
         }
         COMPILE::JS {
-            var ret :Number = new DataView(ba).getFloat32(_position,_endian == Endian.LITTLE_ENDIAN);
+            var ret :Number = getDataView().getFloat32(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 4;
             return ret;
         }
@@ -749,7 +760,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             return ba.readDouble();
         }
         COMPILE::JS {
-            var ret:Number = new DataView(ba).getFloat64(_position,_endian == Endian.LITTLE_ENDIAN);
+            var ret:Number = getDataView().getFloat64(_position,_endian == Endian.LITTLE_ENDIAN);
             _position += 8;
             return ret;
         }
@@ -809,6 +820,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             ba = newView.buffer;
             if (_position > newSize) _position = newSize;
             _typedArray = newView;
+            _dataView = null;
             _len = newSize;
         }
     }
@@ -1067,6 +1079,7 @@ public class BinaryData implements IBinaryDataInput, IBinaryDataOutput
             dest.set(newBytes, offset);
             ba = dest.buffer;
             _typedArray = dest;
+            _dataView = null;
 			_len = mergeUpperBound;
         } else {
             dest = new Uint8Array(ba, offset, newContentLength);


Mime
View raw message