From 0ae886697e09bd010dfdf730843dfa04f453e63b Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Fri, 16 Oct 2009 01:23:07 +0000 Subject: Fix for last commit to allow for gaps in the the list of serialized properties. --- .../carbonado/raw/GenericEncodingStrategy.java | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java index 7f26238..05cc5dd 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericEncodingStrategy.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Vector; import org.cojen.classfile.CodeAssembler; import org.cojen.classfile.Label; @@ -1930,7 +1931,7 @@ public class GenericEncodingStrategy { LocalVariable[] valueRefRef = new LocalVariable[1]; // Used by SERIAL mode. - LocalVariable[] stateVars = null; + List stateVars = null; if (mode == Mode.SERIAL) { stateVars = decodePropertyStates(a, encodedVar, constantOffset, properties); @@ -1996,7 +1997,7 @@ public class GenericEncodingStrategy { if (mode == Mode.SERIAL) { // Load property if initialized, else reset it. - a.loadLocal(stateVars[property.getNumber() >> 4]); + a.loadLocal(stateVars.get(property.getNumber() >> 4)); a.loadConstant(PROPERTY_STATE_MASK << ((property.getNumber() & 0xf) * 2)); a.math(Opcode.IAND); Label isInitialized = a.createLabel(); @@ -2117,10 +2118,13 @@ public class GenericEncodingStrategy { } if (stateVars != null) { - for (int i=0; i { * @param offset offset into byte array * @return local variables with state values */ - private LocalVariable[] decodePropertyStates(CodeAssembler a, LocalVariable encodedVar, - int offset, StorableProperty[] properties) + private List decodePropertyStates(CodeAssembler a, LocalVariable encodedVar, + int offset, StorableProperty[] properties) { - LocalVariable[] stateVars = new LocalVariable[(properties.length + 15) >> 4]; + Vector stateVars = new Vector(); LocalVariable accumVar = a.createLocalVariable(null, TypeDesc.INT); int accumShift = 8; @@ -2587,12 +2591,13 @@ public class GenericEncodingStrategy { StorableProperty property = properties[i]; int stateVarOrdinal = property.getNumber() >> 4; + stateVars.setSize(Math.max(stateVars.size(), stateVarOrdinal + 1)); - if (stateVars[stateVarOrdinal] == null) { - stateVars[stateVarOrdinal] = a.createLocalVariable(null, TypeDesc.INT); + if (stateVars.get(stateVarOrdinal) == null) { + stateVars.set(stateVarOrdinal, a.createLocalVariable(null, TypeDesc.INT)); a.loadThis(); a.loadField(PROPERTY_STATE_FIELD_NAME + stateVarOrdinal, TypeDesc.INT); - a.storeLocal(stateVars[stateVarOrdinal]); + a.storeLocal(stateVars.get(stateVarOrdinal)); } if (accumShift >= 8) { @@ -2644,11 +2649,11 @@ public class GenericEncodingStrategy { a.loadConstant(mask); a.math(Opcode.IAND); - a.loadLocal(stateVars[stateVarOrdinal]); + a.loadLocal(stateVars.get(stateVarOrdinal)); a.loadConstant(~mask); a.math(Opcode.IAND); a.math(Opcode.IOR); - a.storeLocal(stateVars[stateVarOrdinal]); + a.storeLocal(stateVars.get(stateVarOrdinal)); accumShift += accumPack; } -- cgit v1.2.3