Commit 1768c58
Performance fix: avoid unnecessary
* Add `convert(::Type{T}, x::T) where {T<:FD} = x`
This fixes unnecessary copies on `setindex!`, etc.
* Remove "copy constructor" after correct `convert` fix
The "copy constructor" is no longer necessary now that a no-op
`convert` is added, since by default construction falls back to convert.
To verify, after this change, the performance is still correct:
```
julia> f = FixedPointDecimals.FixedDecimal{Int128,2}(3.25)
FixedDecimal{Int128,2}(3.25)
julia> @Btime x = FixedPointDecimals.FixedDecimal{Int128, 2}($f)
0.036 ns (0 allocations: 0 bytes)
FixedDecimal{Int128,2}(3.25)
```
And `@code_native` shows this to be a simple reinterpret.convert on setindex!、copy when type is same. (#38)1 parent d87debb commit 1768c58
1 file changed
+2
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | 102 | | |
106 | 103 | | |
107 | 104 | | |
| |||
274 | 271 | | |
275 | 272 | | |
276 | 273 | | |
| 274 | + | |
| 275 | + | |
277 | 276 | | |
278 | 277 | | |
279 | 278 | | |
| |||
0 commit comments