marianoguerra / json.human.js

Convert JSON to human readable HTML
http://marianoguerra.github.io/json.human.js/
975 stars 79 forks source link

Date and "empty objects" that are not objects. #35

Closed joar closed 8 years ago

joar commented 8 years ago

Add support for Date objects and "empty objects" that are not objects. Uses obj.toString() to display the object.

Also convert "CONSTANTS" to be bitmask-compatible and replace switch statement with if statement in order to be able to use bitmasks.

marianoguerra commented 8 years ago

hi, thanks for your patch!

just some observations, did you changed to ifs only to use bitmasks? why not just introduce another constant for special objects and keep the switch?

I'm using this lib in a performance sensitive place (hundreds of potentially big objects) and when I update this lib, if my benchmarks show that the if is slower I will revert back to a switch statement.

just want to know if there's a performance reason that I don't know of (I would expect switch to be optimized to a jump table but the "if" solution not, but maybe there's an optimization I'm not aware of)

joar commented 8 years ago

I chose if..else-if..else because it was more sraight-forward when dealing with bitmasks.

I've put together a perf test which compares the isolated bitmask-in-switch and bitmask-in-if behaviour and the difference is minimal.

marianoguerra commented 8 years ago

ok, thanks for the perf test and the patch!