Skip to content

Commit

Permalink
optimization(win32-api): BufferTypeFactory()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jun 28, 2022
1 parent 8ee97d3 commit ea17275
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions packages/win32-api/src/lib/fixed-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,44 @@ export interface BufferType extends Type {
* @ref https://gist.github.com/TooTallNate/80ac2d94b950216a2705
*/
export function BufferTypeFactory(length: number, encoding?: BufferEncoding): BufferType {
assert(length >= 0)

const inst = Object.create(types.byte, {
constructor: {
configurable: true,
enumerable: false,
writable: true,
value: BufferTypeFactory,
},
}) as BufferType

Object.defineProperty(inst, 'size', {
configurable: true,
enumerable: true,
writable: false,
value: length,
})

Object.defineProperty(inst, 'encoding', {
configurable: true,
enumerable: true,
writable: true,
value: encoding,
})


Object.defineProperty(inst, 'get', {
configurable: true,
enumerable: true,
writable: true,
value: getFn,
})

Object.defineProperty(inst, 'set', {
configurable: true,
enumerable: true,
writable: true,
value: setFn,
})
size: {
configurable: true,
enumerable: true,
writable: false,
value: length,
},

encoding: {
configurable: true,
enumerable: true,
writable: true,
value: encoding,
},

get: {
configurable: true,
enumerable: true,
writable: true,
value: getFn,
},

set: {
configurable: true,
enumerable: true,
writable: true,
value: setFn,
},
}) as BufferType

return inst
}
Expand Down

0 comments on commit ea17275

Please sign in to comment.