arson icon indicating copy to clipboard operation
arson copied to clipboard

Intern object keys as well as values.

Open benjamn opened this issue 8 years ago • 1 comments

Instead of encoding objects as object literals with (possibly repeated) string keys, this commit encodes them as an array of (interned) keys and values:

> ARSON.encode([{lonnngKeyName:"a",a:true},{b:false,lonnngKeyName:"b"}])
'[[1,2],["o",3,4,4,5],["o",6,7,3,6],"lonnngKeyName","a",true,"b",false]'
> ARSON.decode(_)
[ { lonnngKeyName: 'a', a: true },
  { b: false, lonnngKeyName: 'b' } ]

Notice that the key string "lonnngKeyName" appears only once in the encoding.

Here's the output without this change applied:

> ARSON.encode([{lonnngKeyName:"a",a:true},{b:false,lonnngKeyName:"b"}])
'[[1,2],{"lonnngKeyName":3,"a":4},{"b":5,"lonnngKeyName":6},"a",true,false,"b"]'
> ARSON.decode(_)
[ { lonnngKeyName: 'a', a: true },
  { b: false, lonnngKeyName: 'b' } ]

benjamn avatar Mar 18 '17 17:03 benjamn

See #16

KnorpelSenf avatar Jul 21 '24 16:07 KnorpelSenf