Skip to content

Commit ad631c6

Browse files
committed
Add comments to json differ.
1 parent bc98363 commit ad631c6

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

go/store/prolly/tree/indexed_json_diff.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,29 @@ func NewIndexedJsonDiffer(ctx context.Context, from, to IndexedJsonDocument) (*I
4646

4747
var currentFromCursor, currentToCursor *JsonCursor
4848
if differ.from == nil {
49-
// This can happen when either document fits in a single chunk.
50-
// We don't use the chunk differ in this case, and instead we create the cursors without it.
49+
// The "from" document fits inside a single chunk.
50+
// We can't create the "from" cursor from the differ, so we create it here instead.
5151
diffKey := []byte{byte(startOfValue)}
5252
currentFromCursor, err = newJsonCursorAtStartOfChunk(ctx, from.m.NodeStore, from.m.Root, diffKey)
5353
if err != nil {
5454
return nil, err
5555
}
56+
// Advance the cursor past the "beginning of document" location, so that it aligns with the "to" cursor no matter what.
5657
err = advanceCursor(ctx, &currentFromCursor)
5758
if err != nil {
5859
return nil, err
5960
}
6061
}
6162

6263
if differ.to == nil {
63-
// This can happen when either document fits in a single chunk.
64-
// We don't use the chunk differ in this case, and instead we create the cursors without it.
64+
// The "to" document fits inside a single chunk.
65+
// We can't create the "from" cursor from the differ, so we create it here instead.
6566
diffKey := []byte{byte(startOfValue)}
6667
currentToCursor, err = newJsonCursorAtStartOfChunk(ctx, to.m.NodeStore, to.m.Root, diffKey)
6768
if err != nil {
6869
return nil, err
6970
}
71+
// Advance the cursor past the "beginning of document" location, so that it aligns with the "from" cursor no matter what.
7072
err = advanceCursor(ctx, &currentToCursor)
7173
if err != nil {
7274
return nil, err
@@ -161,9 +163,12 @@ func (jd *IndexedJsonDiffer) Next(ctx context.Context) (diff JsonDiff, err error
161163
return JsonDiff{}, err
162164
}
163165
} else if jd.currentFromCursor == nil {
164-
// We exhausted the current `from` chunk but not the `to` chunk. Since the chunk boundaries don't align on
166+
// We exhausted the current `from` chunk but not the current `to` chunk. Since the chunk boundaries don't align on
165167
// the same key, we need to continue into the next chunk.
166168

169+
// Alternatively, the "to" cursor was created during construction because the "to" document fit in a single chunk,
170+
// and the "from" cursor hasn't been created yet.
171+
167172
jd.currentFromCursor, err = newJsonCursorFromCursor(ctx, jd.differ.from)
168173
if err != nil {
169174
return JsonDiff{}, err
@@ -175,9 +180,12 @@ func (jd *IndexedJsonDiffer) Next(ctx context.Context) (diff JsonDiff, err error
175180
}
176181
continue
177182
} else if jd.currentToCursor == nil {
178-
// We exhausted the current `to` chunk but not the `from` chunk. Since the chunk boundaries don't align on
183+
// We exhausted the current `to` chunk but not the current `from` chunk. Since the chunk boundaries don't align on
179184
// the same key, we need to continue into the next chunk.
180185

186+
// Alternatively, the "from" cursor was created during construction because the "from" document fit in a single chunk,
187+
// and the "to" cursor hasn't been created yet.
188+
181189
jd.currentToCursor, err = newJsonCursorFromCursor(ctx, jd.differ.to)
182190
if err != nil {
183191
return JsonDiff{}, err

0 commit comments

Comments
 (0)