jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1005820 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util: BundleReader.java BundleWriter.java
Date Fri, 08 Oct 2010 13:43:24 GMT
Author: jukka
Date: Fri Oct  8 13:43:24 2010
New Revision: 1005820

URL: http://svn.apache.org/viewvc?rev=1005820&view=rev
Log:
JCR-2762: Optimize bundle serialization

Move the binding version byte to the constructor for easier extensibility

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java?rev=1005820&r1=1005819&r2=1005820&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleReader.java
Fri Oct  8 13:43:24 2010
@@ -48,15 +48,20 @@ class BundleReader {
 
     private final DataInputStream in;
 
+    private final int version;
+
     /**
      * Creates a new bundle deserializer.
      *
      * @param binding bundle binding
      * @param stream stream from which the bundle is read
+     * @throws IOException if an I/O error occurs.
      */
-    public BundleReader(BundleBinding binding, InputStream stream) {
+    public BundleReader(BundleBinding binding, InputStream stream)
+            throws IOException {
         this.binding = binding;
         this.in = new DataInputStream(stream);
+        this.version = in.readUnsignedByte();
     }
 
     /**
@@ -69,13 +74,11 @@ class BundleReader {
     public NodePropBundle readBundle(NodeId id) throws IOException {
         NodePropBundle bundle = new NodePropBundle(id);
 
-        // read version and primary type...special handling
-        int index = in.readInt();
-
-        // get version
-        int version = (index >> 24) & 0xff;
-        index &= 0x00ffffff;
-        String uri = binding.nsIndex.indexToString(index);
+        // read primary type...special handling
+        int a = in.readUnsignedByte();
+        int b = in.readUnsignedByte();
+        int c = in.readUnsignedByte();
+        String uri = binding.nsIndex.indexToString(a << 16 | b << 8 | c);
         String local = binding.nameIndex.indexToString(in.readInt());
         Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local);
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java?rev=1005820&r1=1005819&r2=1005820&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/BundleWriter.java
Fri Oct  8 13:43:24 2010
@@ -54,10 +54,13 @@ class BundleWriter {
      *
      * @param binding bundle binding
      * @param stream stream to which the bundle will be written
+     * @throws IOException if an I/O error occurs.
      */
-    public BundleWriter(BundleBinding binding, OutputStream stream) {
+    public BundleWriter(BundleBinding binding, OutputStream stream)
+            throws IOException {
         this.binding = binding;
         this.out = new DataOutputStream(stream);
+        this.out.writeByte(BundleBinding.VERSION_CURRENT);
     }
 
     /**
@@ -71,10 +74,12 @@ class BundleWriter {
         long size = out.size();
 
         // primaryType and version
-        out.writeInt(
-                (BundleBinding.VERSION_CURRENT << 24)
-                | binding.nsIndex.stringToIndex(bundle.getNodeTypeName().getNamespaceURI()));
-        out.writeInt(binding.nameIndex.stringToIndex(bundle.getNodeTypeName().getLocalName()));
+        Name type = bundle.getNodeTypeName();
+        int index = binding.nsIndex.stringToIndex(type.getNamespaceURI());
+        out.writeByte(index >>> 16);
+        out.writeByte(index >>> 8);
+        out.writeByte(index);
+        out.writeInt(binding.nameIndex.stringToIndex(type.getLocalName()));
 
         // parentUUID
         writeNodeId(bundle.getParentId());



Mime
View raw message