Skip to content

Commit

Permalink
perf(CopyTransformer): Move identity check to the beginning.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyadi committed Jan 15, 2024
1 parent 58c0485 commit 0555d64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* dx(`TypeCheck`): Now accept `MixedType` as an argument.
* test: Mapping test first version.
* refactor: rename `RefuseToHandleException` to `RefuseToTransformException`.
* perf(`CopyTransformer`): Move identity check to the beginning.

## 0.5.10

Expand Down
8 changes: 4 additions & 4 deletions src/Transformer/CopyTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function transform(
?Type $targetType,
Context $context
): mixed {
if ($targetType !== null && !TypeCheck::isVariableInstanceOf($source, $targetType)) {
throw new RefuseToTransformException();
}

if (!is_object($source)) {
return $source;
}
Expand All @@ -42,10 +46,6 @@ public function transform(

$result = clone $source;

if ($targetType !== null && !TypeCheck::isVariableInstanceOf($result, $targetType)) {
throw new RefuseToTransformException();
}

return $result;
}

Expand Down

0 comments on commit 0555d64

Please sign in to comment.