Skip to content

Commit

Permalink
The $i is not necessary for buffer serialize.
Browse files Browse the repository at this point in the history
Closes #586.
  • Loading branch information
flatheadmill committed Aug 21, 2020
1 parent 55002ef commit 5498c6d
Show file tree
Hide file tree
Showing 26 changed files with 65 additions and 81 deletions.
4 changes: 3 additions & 1 deletion declare.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ exports.serialize = function (field) {
}
break
case 'lengthEncoded': {
variables.i = true
if (field.encoding) {
field.encoding.map(declare)
}
if (field.fields[0].type != 'buffer') {
variables.i = true
}
if (field.fields[0].type == 'buffer' && ! field.fields[0].concat) {
variables.I = true
}
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/chunked.serializer.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $buffer, $start) {
let $i = [], $I = []
let $I = []

$buffer[$start++] = object.nudge & 0xff

Expand Down
4 changes: 2 additions & 2 deletions test/generated/array/chunked.serializer.bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = [], $I = []
let $I = []

if ($end - $start < 3 + object.array.reduce((sum, buffer) => sum + buffer.length, 0)) {
return $incremental.object(object, 0, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 0, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff
Expand Down
10 changes: 5 additions & 5 deletions test/generated/array/chunked.serializer.chk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = [], $I = []
let $I = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 0, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff

if ($end - $start < 1) {
return $incremental.object(object, 2, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 2, $I)($buffer, $start, $end)
}

$I[0] = object.array.reduce((sum, buffer) => sum + buffer.length, 0)
$buffer[$start++] = $I[0] & 0xff

if ($end - $start < 0 + object.array.reduce((sum, buffer) => sum + buffer.length, 0)) {
return $incremental.object(object, 5, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 5, $I)($buffer, $start, $end)
}

{
Expand All @@ -30,7 +30,7 @@ module.exports = function ({ $incremental, $lookup }) {
}

if ($end - $start < 1) {
return $incremental.object(object, 6, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 6, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.sentry & 0xff
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/chunked.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $step = 0, $i = [], $I = []) {
return function (object, $step = 0, $I = []) {
let $_, $bite, $copied = 0, $offset = 0, $index = 0

return function $serialize ($buffer, $start, $end) {
Expand Down
2 changes: 0 additions & 2 deletions test/generated/array/concat.serializer.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $buffer, $start) {
let $i = []

$buffer[$start++] = object.nudge & 0xff

$buffer[$start++] = object.array.length & 0xff
Expand Down
4 changes: 1 addition & 3 deletions test/generated/array/concat.serializer.bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = []

if ($end - $start < 3 + object.array.length * 1) {
return $incremental.object(object, 0, $i)($buffer, $start, $end)
return $incremental.object(object, 0)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff
Expand Down
10 changes: 4 additions & 6 deletions test/generated/array/concat.serializer.chk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i)($buffer, $start, $end)
return $incremental.object(object, 0)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff

if ($end - $start < 1) {
return $incremental.object(object, 2, $i)($buffer, $start, $end)
return $incremental.object(object, 2)($buffer, $start, $end)
}

$buffer[$start++] = object.array.length & 0xff

if ($end - $start < 0 + object.array.length) {
return $incremental.object(object, 4, $i)($buffer, $start, $end)
return $incremental.object(object, 4)($buffer, $start, $end)
}

object.array.copy($buffer, $start, 0, object.array.length)
$start += object.array.length

if ($end - $start < 1) {
return $incremental.object(object, 5, $i)($buffer, $start, $end)
return $incremental.object(object, 5)($buffer, $start, $end)
}

$buffer[$start++] = object.sentry & 0xff
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/concat.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $step = 0, $i = []) {
return function (object, $step = 0) {
let $_, $bite, $copied = 0

return function $serialize ($buffer, $start, $end) {
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/conditional/chunked.serializer.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $buffer, $start) {
let $i = [], $I = []
let $I = []

$buffer[$start++] = object.nudge & 0xff

Expand Down
10 changes: 5 additions & 5 deletions test/generated/array/conditional/chunked.serializer.bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = [], $I = []
let $I = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 0, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff

$I[0] = object.array.reduce((sum, buffer) => sum + buffer.length, 0)
if ((value => value < 128)($I[0])) {
if ($end - $start < 1) {
return $incremental.object(object, 4, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 4, $I)($buffer, $start, $end)
}

$buffer[$start++] = $I[0] & 0xff
} else {
if ($end - $start < 2) {
return $incremental.object(object, 6, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 6, $I)($buffer, $start, $end)
}

$buffer[$start++] = $I[0] >>> 7 & 0x7f | 0x80
$buffer[$start++] = $I[0] & 0x7f
}

if ($end - $start < 1 + object.array.reduce((sum, buffer) => sum + buffer.length, 0)) {
return $incremental.object(object, 9, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 9, $I)($buffer, $start, $end)
}

{
Expand Down
12 changes: 6 additions & 6 deletions test/generated/array/conditional/chunked.serializer.chk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = [], $I = []
let $I = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 0, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff

$I[0] = object.array.reduce((sum, buffer) => sum + buffer.length, 0)
if ((value => value < 128)($I[0])) {
if ($end - $start < 1) {
return $incremental.object(object, 4, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 4, $I)($buffer, $start, $end)
}

$buffer[$start++] = $I[0] & 0xff
} else {
if ($end - $start < 2) {
return $incremental.object(object, 6, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 6, $I)($buffer, $start, $end)
}

$buffer[$start++] = $I[0] >>> 7 & 0x7f | 0x80
$buffer[$start++] = $I[0] & 0x7f
}

if ($end - $start < 0 + object.array.reduce((sum, buffer) => sum + buffer.length, 0)) {
return $incremental.object(object, 9, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 9, $I)($buffer, $start, $end)
}

{
Expand All @@ -39,7 +39,7 @@ module.exports = function ({ $incremental, $lookup }) {
}

if ($end - $start < 1) {
return $incremental.object(object, 10, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 10, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.sentry & 0xff
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/conditional/chunked.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $step = 0, $i = [], $I = []) {
return function (object, $step = 0, $I = []) {
let $_, $bite, $copied = 0, $offset = 0, $index = 0

return function $serialize ($buffer, $start, $end) {
Expand Down
2 changes: 0 additions & 2 deletions test/generated/array/conditional/concat.serializer.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $buffer, $start) {
let $i = []

$buffer[$start++] = object.nudge & 0xff

if ((value => value < 128)(object.array.length)) {
Expand Down
10 changes: 4 additions & 6 deletions test/generated/array/conditional/concat.serializer.bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i)($buffer, $start, $end)
return $incremental.object(object, 0)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff

if ((value => value < 128)(object.array.length)) {
if ($end - $start < 1) {
return $incremental.object(object, 3, $i)($buffer, $start, $end)
return $incremental.object(object, 3)($buffer, $start, $end)
}

$buffer[$start++] = object.array.length & 0xff
} else {
if ($end - $start < 2) {
return $incremental.object(object, 5, $i)($buffer, $start, $end)
return $incremental.object(object, 5)($buffer, $start, $end)
}

$buffer[$start++] = object.array.length >>> 7 & 0x7f | 0x80
$buffer[$start++] = object.array.length & 0x7f
}

if ($end - $start < 1 + object.array.length * 1) {
return $incremental.object(object, 8, $i)($buffer, $start, $end)
return $incremental.object(object, 8)($buffer, $start, $end)
}

object.array.copy($buffer, $start, 0, object.array.length)
Expand Down
12 changes: 5 additions & 7 deletions test/generated/array/conditional/concat.serializer.chk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i)($buffer, $start, $end)
return $incremental.object(object, 0)($buffer, $start, $end)
}

$buffer[$start++] = object.nudge & 0xff

if ((value => value < 128)(object.array.length)) {
if ($end - $start < 1) {
return $incremental.object(object, 3, $i)($buffer, $start, $end)
return $incremental.object(object, 3)($buffer, $start, $end)
}

$buffer[$start++] = object.array.length & 0xff
} else {
if ($end - $start < 2) {
return $incremental.object(object, 5, $i)($buffer, $start, $end)
return $incremental.object(object, 5)($buffer, $start, $end)
}

$buffer[$start++] = object.array.length >>> 7 & 0x7f | 0x80
$buffer[$start++] = object.array.length & 0x7f
}

if ($end - $start < 0 + object.array.length) {
return $incremental.object(object, 8, $i)($buffer, $start, $end)
return $incremental.object(object, 8)($buffer, $start, $end)
}

object.array.copy($buffer, $start, 0, object.array.length)
$start += object.array.length

if ($end - $start < 1) {
return $incremental.object(object, 9, $i)($buffer, $start, $end)
return $incremental.object(object, 9)($buffer, $start, $end)
}

$buffer[$start++] = object.sentry & 0xff
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/conditional/concat.serializer.inc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $step = 0, $i = []) {
return function (object, $step = 0) {
let $_, $bite, $copied = 0

return function $serialize ($buffer, $start, $end) {
Expand Down
2 changes: 1 addition & 1 deletion test/generated/array/switch/chunked.serializer.all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function ({ $lookup }) {
return {
object: function () {
return function (object, $buffer, $start) {
let $i = [], $I = []
let $I = []

$buffer[$start++] = object.type & 0xff

Expand Down
10 changes: 5 additions & 5 deletions test/generated/array/switch/chunked.serializer.bff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = function ({ $incremental, $lookup }) {
object: function () {
return function (object) {
return function ($buffer, $start, $end) {
let $i = [], $I = []
let $I = []

if ($end - $start < 1) {
return $incremental.object(object, 0, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 0, $I)($buffer, $start, $end)
}

$buffer[$start++] = object.type & 0xff
Expand All @@ -16,7 +16,7 @@ module.exports = function ({ $incremental, $lookup }) {
case 0:

if ($end - $start < 1) {
return $incremental.object(object, 4, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 4, $I)($buffer, $start, $end)
}

$buffer[$start++] = $I[0] & 0xff
Expand All @@ -26,7 +26,7 @@ module.exports = function ({ $incremental, $lookup }) {
default:

if ($end - $start < 2) {
return $incremental.object(object, 6, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 6, $I)($buffer, $start, $end)
}

$buffer[$start++] = $I[0] >>> 8 & 0xff
Expand All @@ -36,7 +36,7 @@ module.exports = function ({ $incremental, $lookup }) {
}

if ($end - $start < 1 + object.array.reduce((sum, buffer) => sum + buffer.length, 0)) {
return $incremental.object(object, 8, $i, $I)($buffer, $start, $end)
return $incremental.object(object, 8, $I)($buffer, $start, $end)
}

{
Expand Down
Loading

0 comments on commit 5498c6d

Please sign in to comment.