fleece-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hendrik Dev <hendrikde...@gmail.com>
Subject JsonValue immutability
Date Tue, 15 Jul 2014 11:39:59 GMT
To open another discussion ;-) i looked on the JsonValue
implementations regarding immutability (as the API requires).

Looks like that doing real immutability have a really bad performance
impact (at least in my prototype implementation which is here
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35).
So i understand why the initial implementation deals with the
JsonArrayImpl.addInternal() and JsonObjectImpl.putInternal(). But if i
were a nitpicker i would say thats not immutable :-)
The main performance impact is due to the builder implementations i
think if the values are really immutable.

But at least the JsonValue implementations itself can be immutable
without big perf drawbacks hopefully. To make them "more" immutable
(and keep the put/addInternal()) i suggest:

For JsonArrayImpl
- getValuesAs() should return unmodifiable list
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35#commitcomment-7011110

- subList(int fromIndex, int toIndex) should return unmodifiable list
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35#commitcomment-7011145

- listIterator(int index) disallow to change list
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35#commitcomment-7011156

- make class final

- make hashcode caching threadsafe (int terms of "volatile")
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35#commitcomment-7011019

- make addInternal package private


For JasonObjectImpl
- keySet() should return unmodifiable set

- values()  should return unmodifiable collection

- entrySet() should return unmodifiable set (tricky ->
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/util/Collections.java#1366)

- make class final

- make hashcode caching threadsafe (int terms of "volatile")
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35#commitcomment-7011019

- make putInternal package private


For the other JsonValue implementations
- make classes final
- make hashcode caching threadsafe (int terms of "volatile")
https://github.com/salyh/fleece_master/commit/8ce227915ef5bcaa695fa354b7126762a2221d35#commitcomment-7011019

Your opinion?

Regards
Hendrik



-- 
Hendrik Saly (salyh, hendrikdev22)
@hendrikdev22
PGP: 0x22D7F6EC

Mime
View raw message