Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intern object keys as well as values. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benjamn
Copy link
Owner

@benjamn benjamn commented Mar 18, 2017

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' } ]

@KnorpelSenf
Copy link

See #16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants