Skip to content

Commit 0b2b7e7

Browse files
committed
remove remaining deep copies
1 parent 5c6c265 commit 0b2b7e7

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/cmap/command_monitoring_events.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
LEGACY_HELLO_COMMAND,
77
LEGACY_HELLO_COMMAND_CAMEL_CASE
88
} from '../constants';
9-
import { calculateDurationInMs, deepCopy } from '../utils';
9+
import { calculateDurationInMs } from '../utils';
1010
import {
1111
DocumentSequence,
1212
OpMsgRequest,
@@ -276,15 +276,15 @@ function extractCommand(command: WriteProtocolMessageType): Document {
276276
result = { find: collectionName(command) };
277277
Object.keys(LEGACY_FIND_QUERY_MAP).forEach(key => {
278278
if (command.query[key] != null) {
279-
result[LEGACY_FIND_QUERY_MAP[key]] = deepCopy(command.query[key]);
279+
result[LEGACY_FIND_QUERY_MAP[key]] = { ...command.query[key] };
280280
}
281281
});
282282
}
283283

284284
Object.keys(LEGACY_FIND_OPTIONS_MAP).forEach(key => {
285285
const legacyKey = key as keyof typeof LEGACY_FIND_OPTIONS_MAP;
286286
if (command[legacyKey] != null) {
287-
result[LEGACY_FIND_OPTIONS_MAP[legacyKey]] = deepCopy(command[legacyKey]);
287+
result[LEGACY_FIND_OPTIONS_MAP[legacyKey]] = command[legacyKey];
288288
}
289289
});
290290

@@ -304,19 +304,13 @@ function extractCommand(command: WriteProtocolMessageType): Document {
304304
return result;
305305
}
306306

307-
const clonedQuery: Record<string, unknown> = {};
308-
const clonedCommand: Record<string, unknown> = {};
307+
let clonedQuery: Record<string, unknown> = {};
308+
const clonedCommand: Record<string, unknown> = { ...command };
309309
if (command.query) {
310-
for (const k in command.query) {
311-
clonedQuery[k] = deepCopy(command.query[k]);
312-
}
310+
clonedQuery = { ...command.query };
313311
clonedCommand.query = clonedQuery;
314312
}
315313

316-
for (const k in command) {
317-
if (k === 'query') continue;
318-
clonedCommand[k] = deepCopy((command as unknown as Record<string, unknown>)[k]);
319-
}
320314
return command.query ? clonedQuery : clonedCommand;
321315
}
322316

0 commit comments

Comments
 (0)