Skip to content

Commit c4caba1

Browse files
committed
merge-ort: clarify the interning of strings in opt->priv->path
Because merge-ort is dealing with potentially all the pathnames in the repository, it sometimes needs to do an awful lot of string comparisons. Because of this, struct merge_options_internal's path member was envisioned from the beginning to contain an interned value for every path in order to allow us to compare strings via pointer comparison instead of using strcmp. See * 5b59c3d (merge-ort: setup basic internal data structures, 2020-12-13) * f591c47 (merge-ort: copy and adapt merge_3way() from merge-recursive.c, 2021-01-01) for some of the early comments. However, the original comment was slightly misleading when it switched from mentioning paths to only mentioning directories. Fix that, and while at it also point to an example in the code which applies the extra needed care to permit the pointer comparison optimization. Signed-off-by: Elijah Newren <[email protected]>
1 parent 29b5e00 commit c4caba1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

merge-ort.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,14 @@ struct merge_options_internal {
316316
* (e.g. "drivers/firmware/raspberrypi.c").
317317
* * store all relevant paths in the repo, both directories and
318318
* files (e.g. drivers, drivers/firmware would also be included)
319-
* * these keys serve to intern all the path strings, which allows
320-
* us to do pointer comparison on directory names instead of
321-
* strcmp; we just have to be careful to use the interned strings.
319+
* * these keys serve to intern *all* path strings, which allows us
320+
* to do pointer comparisons on file & directory names instead of
321+
* using strcmp; however, for this pointer-comparison optimization
322+
* to work, any code path that independently computes a path needs
323+
* to check for it existing in this strmap, and if so, point to
324+
* the path in this strmap instead of their computed copy. See
325+
* the "reuse known pointer" comment in
326+
* apply_directory_rename_modifications() for an example.
322327
*
323328
* The values of paths:
324329
* * either a pointer to a merged_info, or a conflict_info struct

0 commit comments

Comments
 (0)