Use Slice.literal for fast_float when supported, part 2#16261
Conversation
| LARGE_POWER_OF_5 = Slice[ | ||
| 1414648277510068013_u64, 9180637584431281687_u64, 4539964771860779200_u64, | ||
| 10482974169319127550_u64, 198276706040285095_u64, | ||
| {% if compare_versions(Crystal::VERSION, "1.16.0") < 0 %} |
There was a problem hiding this comment.
thought: The value lists are identical between both types. We could reduce code duplication by making only the outer layer conditional:
{% begin %}
{% if compare_versions(Crystal::VERSION, "1.16.0") < 0 %}
[
{% else %}
Slice(UInt64).literal(
{% end %}
1_u64,
# ...
7450580596923828125_u64,
{% if compare_versions(Crystal::VERSION, "1.16.0") < 0 %}
]
{% else %}
)
{% end %}
{% end %}The added overhead won't make this much appealing for very short slices. But it might be a good idea for the bigger ones? WDYT?
There was a problem hiding this comment.
ping @HertzDevil any thoughts on this?
It shouldn't be a blocker, so I'd like to move on if you don't think it's worth it.
There was a problem hiding this comment.
Duplicating the values is unfortunate but the alternative impacts readability, so I'm not sure it's really better.
Aside: maybe a macro def could help if we supported them, though it would be very inefficient (lots of allocations & transformations) so I'm not sure it would be very useful, especially for large literals and static data that won't change.
macro def slice_literal(type, *values)
{% if compare_versions(Crystal::VERSION, "1.16.0") < 0 %}
Slice({{type}}.literal({{values.splat}})
{% else %}
[{{values.splat}}]
{% end %}
end
LARGE_POWER_OF_5 = {{ slice_literal(UInt64,
1414648277510068013_u64,
9180637584431281687_u64,
4539964771860779200_u64,
10482974169319127550_u64,
198276706040285095_u64,
) }}
Follow-up to #15667.