Skip to content

Commit

Permalink
Change Object.keys by Object.entries
Browse files Browse the repository at this point in the history
  • Loading branch information
uurien committed May 27, 2024
1 parent c6e1c64 commit e56545f
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/dd-trace/src/encode/0.4.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,17 +272,17 @@ class AgentEncoder {
}

_encodeMetaStruct (bytes, value) {
const keys = Array.isArray(value) ? [] : Object.keys(value)
const validKeys = keys.filter(key =>
typeof value[key] === 'string' ||
typeof value[key] === 'number' ||
(value[key] !== null && typeof value[key] === 'object'))
const entries = Array.isArray(value) ? [] : Object.entries(value)
const validEntries = entries.filter(([_, v]) =>
typeof v === 'string' ||
typeof v === 'number' ||
(v !== null && typeof v === 'object'))

this._encodeMapPrefix(bytes, validKeys.length)
this._encodeMapPrefix(bytes, validEntries.length)

for (const key of validKeys) {
this._encodeString(bytes, key)
this._encodeObjectAsByteArray(bytes, value[key])
for (const [k, v] of validEntries) {
this._encodeString(bytes, k)
this._encodeObjectAsByteArray(bytes, v)
}
}

Expand Down Expand Up @@ -316,17 +316,17 @@ class AgentEncoder {
}

_encodeObjectAsMap (bytes, value, circularReferencesDetector) {
const keys = Object.keys(value)
const validKeys = keys.filter(key =>
typeof value[key] === 'string' ||
typeof value[key] === 'number' ||
(value[key] !== null && typeof value[key] === 'object' && !circularReferencesDetector.has(value[key])))
const entries = Object.entries(value)
const validEntries = entries.filter(([_, v]) =>
typeof v === 'string' ||
typeof v === 'number' ||
(v !== null && typeof v === 'object' && !circularReferencesDetector.has(v)))

this._encodeMapPrefix(bytes, validKeys.length)
this._encodeMapPrefix(bytes, validEntries.length)

for (const key of validKeys) {
this._encodeString(bytes, key)
this._encodeObject(bytes, value[key], circularReferencesDetector)
for (const [k, v] of validEntries) {
this._encodeString(bytes, k)
this._encodeObject(bytes, v, circularReferencesDetector)
}
}

Expand Down

0 comments on commit e56545f

Please sign in to comment.