Skip to content

Commit

Permalink
Revert "perf(NODE-6356): Improve serialization performance (#709)"
Browse files Browse the repository at this point in the history
This reverts commit 61537f5.
  • Loading branch information
nbbeeken committed Nov 21, 2024
1 parent dbeda2f commit 43f6403
Show file tree
Hide file tree
Showing 7 changed files with 202 additions and 249 deletions.
3 changes: 1 addition & 2 deletions src/bson_value.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { BSON_MAJOR_VERSION } from './constants';
import { type InspectFn } from './parser/utils';
import { BSON_VERSION_SYMBOL } from './constants';

/** @public */
export abstract class BSONValue {
/** @public */
public abstract get _bsontype(): string;

/** @internal */
get [BSON_VERSION_SYMBOL](): typeof BSON_MAJOR_VERSION {
get [Symbol.for('@@mdb.bson.version')](): typeof BSON_MAJOR_VERSION {
return BSON_MAJOR_VERSION;
}

Expand Down
3 changes: 0 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/** @internal */
export const BSON_MAJOR_VERSION = 6;

/** @internal */
export const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');

/** @internal */
export const BSON_INT32_MAX = 0x7fffffff;
/** @internal */
Expand Down
2 changes: 1 addition & 1 deletion src/decimal128.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Decimal128 extends BSONValue {
super();
if (typeof bytes === 'string') {
this.bytes = Decimal128.fromString(bytes).bytes;
} else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
} else if (isUint8Array(bytes)) {
if (bytes.byteLength !== 16) {
throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
}
Expand Down
5 changes: 2 additions & 3 deletions src/extended_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
BSON_INT32_MIN,
BSON_INT64_MAX,
BSON_INT64_MIN,
BSON_MAJOR_VERSION,
BSON_VERSION_SYMBOL
BSON_MAJOR_VERSION
} from './constants';
import { DBRef, isDBRefLike } from './db_ref';
import { Decimal128 } from './decimal128';
Expand Down Expand Up @@ -359,7 +358,7 @@ function serializeDocument(doc: any, options: EJSONSerializeOptions) {
doc != null &&
typeof doc === 'object' &&
typeof doc._bsontype === 'string' &&
doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION
doc[Symbol.for('@@mdb.bson.version')] !== BSON_MAJOR_VERSION
) {
throw new BSONVersionError();
} else if (isBSONType(doc)) {
Expand Down
2 changes: 1 addition & 1 deletion src/parser/calculate_size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function calculateElement(
if (
value != null &&
typeof value._bsontype === 'string' &&
value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION
value[Symbol.for('@@mdb.bson.version')] !== constants.BSON_MAJOR_VERSION
) {
throw new BSONVersionError();
} else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
Expand Down
Loading

0 comments on commit 43f6403

Please sign in to comment.