Skip to content

Commit 317c714

Browse files
authored
Merge pull request #89 from Tahgolov/refactor/decode-value-types
optimize decodeValueTypes
2 parents e63a80e + 2c299d8 commit 317c714

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

src/main/java/com/reandroid/arsc/value/AttributeDataFormat.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -158,27 +158,25 @@ public static int sum(AttributeDataFormat[] typeValues){
158158
return result;
159159
}
160160

161-
public static AttributeDataFormat[] decodeValueTypes(int data){
162-
AttributeDataFormat[] tmp = new AttributeDataFormat[VALUE_TYPES.length];
163-
int length = 0;
164-
for(AttributeDataFormat typeValue : VALUE_TYPES){
165-
int mask = typeValue.getMask();
166-
if(mask == data){
167-
return new AttributeDataFormat[]{typeValue};
168-
}
169-
if(typeValue == ANY){
170-
continue;
171-
}
172-
if((data & mask) == mask){
173-
tmp[length] = typeValue;
174-
length++;
175-
}
161+
public static AttributeDataFormat[] decodeValueTypes(int data) {
162+
if ((data & 0xffff) == 0xffff) {
163+
return new AttributeDataFormat[]{ANY};
176164
}
177-
if(length == 0){
165+
data &= 0xff;
166+
if (data == 0) {
178167
return null;
179168
}
180-
AttributeDataFormat[] results = new AttributeDataFormat[length];
181-
System.arraycopy(tmp, 0, results, 0, length);
169+
AttributeDataFormat[] results = new AttributeDataFormat[Integer.bitCount(data)];
170+
AttributeDataFormat[] valueTypes = VALUE_TYPES;
171+
int length = valueTypes.length - 1;
172+
int j = 0;
173+
for (int i = 0; i < length; i++) {
174+
if ((data & 1) != 0) {
175+
results[j] = valueTypes[i];
176+
j ++;
177+
}
178+
data = data >> 1;
179+
}
182180
return results;
183181
}
184182
public static AttributeDataFormat[] parseValueTypes(String valuesTypes){

0 commit comments

Comments
 (0)