Commit 7b1004b
committed
combine-diff: simplify intersect_paths() further
Linus once said:
I actually wish more people understood the really core low-level
kind of coding. Not big, complex stuff like the lockless name
lookup, but simply good use of pointers-to-pointers etc. For
example, I've seen too many people who delete a singly-linked
list entry by keeping track of the "prev" entry, and then to
delete the entry, doing something like
if (prev)
prev->next = entry->next;
else
list_head = entry->next;
and whenever I see code like that, I just go "This person
doesn't understand pointers". And it's sadly quite common.
People who understand pointers just use a "pointer to the entry
pointer", and initialize that with the address of the
list_head. And then as they traverse the list, they can remove
the entry without using any conditionals, by just doing a "*pp =
entry->next".
Applying that simplification lets us lose 7 lines from this function
even while adding 2 lines of comment.
I was tempted to squash this into the original commit, but because
the benchmarking described in the commit log is without this
simplification, I decided to keep it a separate follow-up patch.
Signed-off-by: Junio C Hamano <[email protected]>1 parent af82c78 commit 7b1004b
1 file changed
+12
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
23 | 22 | | |
24 | 23 | | |
25 | 24 | | |
| |||
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | | - | |
| 45 | + | |
47 | 46 | | |
48 | 47 | | |
49 | 48 | | |
50 | | - | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 57 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
71 | 61 | | |
72 | 62 | | |
73 | 63 | | |
74 | 64 | | |
| 65 | + | |
75 | 66 | | |
76 | 67 | | |
77 | 68 | | |
| |||
80 | 71 | | |
81 | 72 | | |
82 | 73 | | |
83 | | - | |
84 | | - | |
| 74 | + | |
85 | 75 | | |
86 | 76 | | |
87 | 77 | | |
| |||
0 commit comments