|
2 | 2 |
|
3 | 3 | function Base.map!(f, out::AbstractDictionary, d::AbstractDictionary, d2::AbstractDictionary, ds::AbstractDictionary...) |
4 | 4 | if sharetokens(out, d, d2, ds...) |
5 | | - @inbounds for t in tokens(out) |
6 | | - settokenvalue!(out, t, f(gettokenvalue(d, t), gettokenvalue(d2, t), map(x -> @inbounds(gettokenvalue(x, t)), ds)...)) |
| 5 | + for t in tokens(out) |
| 6 | + y = f(@inbounds(gettokenvalue(d, t)), @inbounds(gettokenvalue(d2, t)), map(x -> @inbounds(gettokenvalue(x, t)), ds)...) |
| 7 | + @inbounds settokenvalue!(out, t, y) |
7 | 8 | end |
8 | 9 | elseif istokenizable(out) |
9 | 10 | @boundscheck if !isequal(keys(out), keys(d)) || !isequal(keys(out), keys(d2)) || any(dict -> !isequal(keys(out), keys(dict)), ds) |
10 | 11 | throw(IndexError("Indices do not match")) |
11 | 12 | end |
12 | | - @inbounds for txs in zip(tokens(out), d, d2, ds...) |
13 | | - t = txs[1] |
14 | | - xs = Base.tail(txs) |
15 | | - settokenvalue!(out, t, f(xs...)) |
| 13 | + for txs in zip(tokens(out), d, d2, ds...) |
| 14 | + t = @inbounds txs[1] |
| 15 | + xs = @inbounds Base.tail(txs) |
| 16 | + y = f(xs...) |
| 17 | + @inbounds settokenvalue!(out, t, y) |
16 | 18 | end |
17 | 19 | else |
18 | 20 | @boundscheck if !isequal(keys(out), keys(d)) || !isequal(keys(out), keys(d2)) || any(dict -> !isequal(keys(out), keys(dict)), ds) |
19 | 21 | throw(IndexError("Indices do not match")) |
20 | 22 | end |
21 | | - @inbounds for ixs in zip(keys(out), d, d2, ds...) |
22 | | - i = ixs[1] |
23 | | - xs = Base.tail(ixs) |
24 | | - out[i] = f(xs...) |
| 23 | + for ixs in zip(keys(out), d, d2, ds...) |
| 24 | + i = @inbounds ixs[1] |
| 25 | + xs = @inbounds Base.tail(ixs) |
| 26 | + y = f(xs...) |
| 27 | + @inbounds out[i] = y |
25 | 28 | end |
26 | 29 | end |
27 | 30 | return out |
|
30 | 33 | # (avoid an _apply for the two-input case) |
31 | 34 | function Base.map!(f, out::AbstractDictionary, d::AbstractDictionary, d2::AbstractDictionary) |
32 | 35 | if sharetokens(out, d, d2) |
33 | | - @inbounds for t in tokens(out) |
34 | | - settokenvalue!(out, t, f(gettokenvalue(d, t), gettokenvalue(d2, t))) |
| 36 | + for t in tokens(out) |
| 37 | + x = @inbounds gettokenvalue(d, t) |
| 38 | + x2 = @inbounds gettokenvalue(d2, t) |
| 39 | + y = f(x, x2) |
| 40 | + @inbounds settokenvalue!(out, t, y) |
35 | 41 | end |
36 | 42 | elseif istokenizable(out) |
37 | 43 | @boundscheck if !isequal(keys(out), keys(d)) || !isequal(keys(out), keys(d2)) |
38 | 44 | throw(IndexError("Indices do not match")) |
39 | 45 | end |
40 | | - @inbounds for (t, x, x2) in zip(tokens(out), d, d2) |
41 | | - settokenvalue!(out, t, f(x, x2)) |
| 46 | + for (t, x, x2) in zip(tokens(out), d, d2) |
| 47 | + y = f(x, x2) |
| 48 | + @inbounds settokenvalue!(out, t, y) |
42 | 49 | end |
43 | 50 | else |
44 | 51 | @boundscheck if !isequal(keys(out), keys(d)) || !isequal(keys(out), keys(d2)) |
45 | 52 | throw(IndexError("Indices do not match")) |
46 | 53 | end |
47 | | - @inbounds for i in keys(out) |
48 | | - out[i] = f(d[i], d2[i]) |
| 54 | + for i in keys(out) |
| 55 | + y = f(@inbounds(d[i]), @inbounds(d2[i])) |
| 56 | + @inbounds out[i] = y |
49 | 57 | end |
50 | 58 | end |
51 | 59 | return out |
52 | 60 | end |
53 | 61 |
|
54 | 62 | function Base.map!(f, out::AbstractDictionary, d::AbstractDictionary) |
55 | 63 | if sharetokens(out, d) |
56 | | - @inbounds for t in tokens(out) |
57 | | - settokenvalue!(out, t, f(gettokenvalue(d, t))) |
| 64 | + for t in tokens(out) |
| 65 | + x = @inbounds gettokenvalue(d, t) |
| 66 | + y = f(x) |
| 67 | + @inbounds settokenvalue!(out, t, y) |
58 | 68 | end |
59 | 69 | elseif istokenizable(out) |
60 | 70 | @boundscheck if !isequal(keys(out), keys(d)) |
61 | 71 | throw(IndexError("Indices do not match")) |
62 | 72 | end |
63 | | - @inbounds for (t, x) in zip(tokens(out), d) |
64 | | - settokenvalue!(out, t, f(x)) |
| 73 | + for (t, x) in zip(tokens(out), d) |
| 74 | + y = f(x) |
| 75 | + @inbounds settokenvalue!(out, t, y) |
65 | 76 | end |
66 | 77 | else |
67 | 78 | @boundscheck if !isequal(keys(out), keys(d)) |
68 | 79 | throw(IndexError("Indices do not match")) |
69 | 80 | end |
70 | | - @inbounds for (i, x) in zip(keys(out), d) |
71 | | - out[i] = f(x) |
| 81 | + for (i, x) in zip(keys(out), d) |
| 82 | + y = f(x) |
| 83 | + @inbounds out[i] = y |
72 | 84 | end |
73 | 85 | end |
74 | 86 | return out |
75 | 87 | end |
76 | 88 |
|
77 | 89 | function Base.map!(f, out::AbstractDictionary) |
78 | 90 | if istokenizable(out) |
79 | | - @inbounds for t in tokens(out) |
80 | | - settokenvalue!(out, t, f()) |
| 91 | + for t in tokens(out) |
| 92 | + y = f() |
| 93 | + @inbounds settokenvalue!(out, t, y) |
81 | 94 | end |
82 | 95 | else |
83 | | - @inbounds for i in keys(out) |
84 | | - out[i] = f() |
| 96 | + for i in keys(out) |
| 97 | + y = f() |
| 98 | + @inbounds out[i] = y |
85 | 99 | end |
86 | 100 | end |
87 | 101 | return out |
|
0 commit comments