Commit 70a74b1
committed
Catch TypeError of non-duplicable objects
In Ruby versions prior to 2.4.x NilClass, Fixnum, Float and Symbol among others
where not cloneable/duplicable and threw a TypeError. In newer versions they
simply return self.
Since rescuing the TypeError is approximately 40x slower than using a predicate
to check whether an object is cloneable or not, one could consider to implement
a `duplicable?` method on Object and conditionally overwrite that on descendants.
See https://stackoverflow.com/questions/49321553/why-is-duplicable-defined-the-way-it-is
However, assuming that this code is not part of a hot code path, that seems
like an unnecessary performance improvement.1 parent 677046a commit 70a74b1
1 file changed
+7
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
| |||
0 commit comments