Skip to content

Commit 68f7bc5

Browse files
committed
Simplifying ensureValidDocument() function
1 parent dee1b2f commit 68f7bc5

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/functions.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
function ensureValidDocument($document) {
99
if ($document instanceof Serializable) {
10-
$document = $document->bsonSerialize();
10+
// do not validate Serializable instances since call to Serializable::bsonSerialize()
11+
// will increase a memory usage by creating array|object copy of the document
12+
return;
1113
}
1214

1315
$arrayDocument = (array) $document;
@@ -21,11 +23,6 @@ function ensureValidDocument($document) {
2123
)
2224
);
2325
}
24-
25-
// Check nested document, if it's not a circular reference to the current $document
26-
if ((is_array($value) || is_object($value)) && !$value === $document) {
27-
ensureValidDocument($value);
28-
}
2926
}
3027
}
3128

0 commit comments

Comments
 (0)