Commit 6632fe0
committed
Memoize
It's a simple function and I believe the result is not supposed to change at runtime.
Strings were not frozen, so it made a bunch of useless allocations too.
I found this method while benchmarking, which was unexpected.
Some basic numbers:
```
# frozen_string_literal: true
require 'unicode/display_width'
require 'benchmark/ips'
Benchmark.ips do |x|
x.report do
Unicode::DisplayWidth.of("foo")
end
x.compare!
end
```
Old gives `207.779k` iterations per second, while new one is `427.344k`.
So more than 2x faster for basic casesEmojiSupport.recommended
1 parent 85692f4 commit 6632fe0
1 file changed
+5
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
| 1 | + | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
| |||
13 | 12 | | |
14 | 13 | | |
15 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
0 commit comments