Skip to content

Commit

Permalink
no need for string lookup on recv
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Dec 29, 2024
1 parent b7956de commit dc2d972
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function generateCode (hyperdispatch) {
str += ' switch (id) {\n'
for (const handler of hyperdispatch.handlers) {
str += ` case ${handler.id}:\n`
str += ` return this._handler${handler.id}(getEncoding(${s(handler.requestType)}).decode(state), context)\n`
str += ` return this._handler${handler.id}(route${handler.id}.enc.decode(state), context)\n`
}
str += ' default:\n'
str += ' throw new Error(\'Handler not found for ID:\' + id)\n'
Expand Down Expand Up @@ -80,7 +80,7 @@ module.exports = function generateCode (hyperdispatch) {
str += '\n'

for (const handler of hyperdispatch.handlers) {
str += 'const dispatch' + handler.id + ' = {\n'
str += 'const route' + handler.id + ' = {\n'
str += ` id: ${handler.id},\n`
str += ` enc: getEncoding(${s(handler.requestType)})\n`
str += '}\n'
Expand All @@ -91,7 +91,7 @@ module.exports = function generateCode (hyperdispatch) {
str += ' switch (name) {\n'
for (const handler of hyperdispatch.handlers) {
str += ` case ${s(handler.name)}:\n`
str += ` return dispatch${handler.id}\n`
str += ` return route${handler.id}\n`
}
str += ' default:\n'
str += ' throw new Error(\'Handler not found for name: \' + name)\n'
Expand Down

0 comments on commit dc2d972

Please sign in to comment.