ICU-12510 set the UResource.Sink.put() Key more simply from the key field of the bundle

X-SVN-Rev: 38654
This commit is contained in:
Markus Scherer 2016-04-27 16:17:11 +00:00
parent 87a89d4df0
commit 8f7dd3149c
2 changed files with 12 additions and 16 deletions

View File

@ -510,25 +510,13 @@ public class ICUResourceBundle extends UResourceBundle {
// When the sink sees the no-fallback/no-inheritance marker, // When the sink sees the no-fallback/no-inheritance marker,
// then it would remove the parent's item. // then it would remove the parent's item.
// We would deserialize parent values even though they are overridden in a child bundle. // We would deserialize parent values even though they are overridden in a child bundle.
// Re-fetch the path keys: They may differ from the original ones
// if we had followed an alias.
int depth = getResDepth();
String[] pathKeys = new String[depth];
getResPathKeys(pathKeys, depth);
int expectedType; int expectedType;
if (sink != null) { if (sink != null) {
expectedType = NONE; expectedType = NONE;
if (depth == 0) {
key.setToEmpty();
} else {
key.setString(pathKeys[depth - 1]);
}
ICUResourceBundleImpl impl = (ICUResourceBundleImpl)this; ICUResourceBundleImpl impl = (ICUResourceBundleImpl)this;
readerValue.reader = impl.wholeBundle.reader; readerValue.reader = impl.wholeBundle.reader;
readerValue.res = impl.getResource(); readerValue.res = impl.getResource();
sink.put(key, readerValue, parent == null); sink.put(key.setString(this.key), readerValue, parent == null);
} else { } else {
expectedType = arraySink != null ? ARRAY : TABLE; expectedType = arraySink != null ? ARRAY : TABLE;
if (getType() == expectedType) { if (getType() == expectedType) {
@ -544,9 +532,14 @@ public class ICUResourceBundle extends UResourceBundle {
// any fallback from the parent bundle is still possible. // any fallback from the parent bundle is still possible.
ICUResourceBundle parentBundle = (ICUResourceBundle)parent; ICUResourceBundle parentBundle = (ICUResourceBundle)parent;
ICUResourceBundle rb; ICUResourceBundle rb;
int depth = getResDepth();
if (depth == 0) { if (depth == 0) {
rb = parentBundle; rb = parentBundle;
} else { } else {
// Re-fetch the path keys: They may differ from the original ones
// if we had followed an alias.
String[] pathKeys = new String[depth];
getResPathKeys(pathKeys, depth);
rb = findResourceWithFallback(pathKeys, 0, parentBundle, null); rb = findResourceWithFallback(pathKeys, 0, parentBundle, null);
} }
if (rb != null && (expectedType == NONE || rb.getType() == expectedType)) { if (rb != null && (expectedType == NONE || rb.getType() == expectedType)) {

View File

@ -65,26 +65,28 @@ public final class UResource {
* @param keyBytes new key string byte array * @param keyBytes new key string byte array
* @param keyOffset new key string offset * @param keyOffset new key string offset
*/ */
public void setBytes(byte[] keyBytes, int keyOffset) { public Key setBytes(byte[] keyBytes, int keyOffset) {
bytes = keyBytes; bytes = keyBytes;
offset = keyOffset; offset = keyOffset;
for (length = 0; keyBytes[keyOffset + length] != 0; ++length) {} for (length = 0; keyBytes[keyOffset + length] != 0; ++length) {}
s = null; s = null;
return this;
} }
/** /**
* Mutates this key to an empty resource key string. * Mutates this key to an empty resource key string.
*/ */
public void setToEmpty() { public Key setToEmpty() {
bytes = null; bytes = null;
offset = length = 0; offset = length = 0;
s = ""; s = "";
return this;
} }
/** /**
* Mutates this key to be equal to the given string. * Mutates this key to be equal to the given string.
*/ */
public void setString(String s) { public Key setString(String s) {
if (s.isEmpty()) { if (s.isEmpty()) {
setToEmpty(); setToEmpty();
} else { } else {
@ -101,6 +103,7 @@ public final class UResource {
} }
this.s = s; this.s = s;
} }
return this;
} }
/** /**