Skip to content

Commit 5a6e0a8

Browse files
Improve comment on DynamicMessage memoized IsInitialized.
PiperOrigin-RevId: 865416143
1 parent 2aa5e03 commit 5a6e0a8

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

java/core/src/main/java/com/google/protobuf/DynamicMessage.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public final class DynamicMessage extends AbstractMessage {
3636
/**
3737
* Stores previously-computed {@code isInitialized} results. {@code isInitialized} can be
3838
* expensive to compute in situations where a large message is converted to a builder, modified,
39-
* and then rebuilt.
39+
* and then rebuilt. A byte field used instead of an idiomatic tristate enum to follow the pattern
40+
* established on gencode, micro-optimizing for better layout.
4041
*/
41-
private transient byte isInitializedMemo = NO_MEMO_PRESENT;
42+
private transient byte memoizedIsInitialized = NO_MEMO_PRESENT;
4243

4344
private static final byte NO_MEMO_PRESENT = -1;
4445
private static final byte IS_INITIALIZED_FALSE = 0;
@@ -226,19 +227,17 @@ static boolean isInitialized(Descriptor type, FieldSet<FieldDescriptor> fields)
226227

227228
@Override
228229
public boolean isInitialized() {
229-
// This section departs slightly from idiomatic style because it is expected that this style
230-
// will optimize better on mobile after processing by technologies like AppReduce.
231-
if (isInitializedMemo == IS_INITIALIZED_TRUE) {
230+
if (memoizedIsInitialized == IS_INITIALIZED_TRUE) {
232231
return true;
233232
}
234-
if (isInitializedMemo == IS_INITIALIZED_FALSE) {
233+
if (memoizedIsInitialized == IS_INITIALIZED_FALSE) {
235234
return false;
236235
}
237236
if (isInitialized(type, fields)) {
238-
isInitializedMemo = IS_INITIALIZED_TRUE;
237+
memoizedIsInitialized = IS_INITIALIZED_TRUE;
239238
return true;
240239
}
241-
isInitializedMemo = IS_INITIALIZED_FALSE;
240+
memoizedIsInitialized = IS_INITIALIZED_FALSE;
242241
return false;
243242
}
244243

0 commit comments

Comments
 (0)