Comments (9)
cJSON_Type
needs 9 bits, not 6:
cJSON_False
cJSON_True
cJSON_NULL
cJSON_Number
cJSON_String
cJSON_Array
cJSON_Object
cJSON_IsReference
cJSON_StringIsConst
That means it would fit in int16_t
but not one byte.
There's a lot of potential for improvement, but I'm not sure what @DaveGamble imagines as the future of cJSON. If we could appoint a version number for the current version, a new version could be made, that does all the breaking changes.
from cjson.
Whups..
I missed the last two ones.... and obviously also miscounted.
from cjson.
I don't really have much of an imagination of the future of cJSON.
The design is naive. If I were writing it now, I'd not use n-trees or linked lists, and instead be a little more crafty with memory allocation.
On the topic of reducing the size of the struct... you could make a union for types, but you're only forestalling the inevitable, which is to require persistence of the original string, lock down direct access to the structs, use a much better memory layout and hence allow 1:1 parse-print, deferred numerical parsing and better CPU+memory usage.
Also, shortening the flags field won't do much if your CPU is aligning struct members. You might have an interesting chip that doesn't do this, but you'll probably pay a cost in misaligned loads for ptrs.
@FSMaxB - where do you see the project going?
from cjson.
What is important to me is that cJSON is currently used by a lot of people, so my goal is to make it as correct, bug free and secure as possible for all the users out there.
I don't think it makes too much sense to add more features to the library than it already has, only minor improvements to the status quo. Feature work should probably be put into one of the other JSON libraries out there.
from cjson.
That's a good argument for rejecting this type of request, and focussing on bug reports, right?
I have done some work towards improving the score for: https://github.com/miloyip/nativejson-benchmark. Perhaps we should set default parse settings to be more strict...? I've a few small changes to the numeric parser that improve things in some obscure edge cases too.
from cjson.
Yes, you're right. Let's focus on bugs. These small changes can be done by the users of the library on a case by case basis anyways.
What do you mean by being more strict? Accepting characters after the end of the JSON is a good feature in my opinion (if that is what you mean), and it can always be turned off by setting require_null_terminated
.
The number parser is really awful because parsing floating point numbers correctly is quite a hard problem. I thought it might be possible to leave this to the C library.
from cjson.
These small changes can be done by the users of the library on a case by case basis anyways.
Agreed.
What do you mean by being more strict? Accepting characters after the end of the JSON is a good feature in my opinion (if that is what you mean), and it can always be turned off by setting require_null_terminated.
Well, I agree with you, but Milo Yip disagrees with both of us.
The number parser is really awful because parsing floating point numbers correctly is quite a hard problem. I thought it might be possible to leave this to the C library.
Yes, it's a deeply hard problem. I have some improvements to commit sometime that get us a few extra points on the nativejson benchmark with this. Leaving it to C library (atof/sscanf) can be problematic for embedded users, and doesn't necessarily do better than we do... But I'll investigate. There's a good argument there for a macro I think.
from cjson.
Well, I agree with you, but Milo Yip disagrees with both of us
But doesn't your PR in his repository fix this by setting require_null_terminated
to 1
?
from cjson.
Yes. But arguably our default should get the high-score. I'm not strongly inclined to argue it, but I can see that an argument could be made. I'd prefer to leave things as they are.
from cjson.
Related Issues (20)
- Cannot Parse JSON HOT 5
- Add a function cJSON_IsEmpty() HOT 4
- JSON Parse Error HOT 12
- Always provide valuestring
- Double Free Vulnerability Discovered in cJSON_Delete Function Through Fuzzing HOT 6
- Fix cmake export to allow cross-compilation with sysroot HOT 1
- Regression on double precision in print_number() when fix a clang compile warning
- A segmentation fault in cJSON_SetValuestring HOT 2
- Can't Install it on PI HOT 2
- cJSON_CreateStringArray and NULL items HOT 4
- Weird Commits HOT 3
- Question: JSON Minifier
- print_number() non guaranteed to be thread safe with floating point numbers
- sorry,delete it
- misc_tests fails on 1.7.18 under Windows HOT 4
- Memory Leak in the cJSON_Free HOT 2
- Bug in print_string_ptr() increment is 4 instead of 5 HOT 2
- Unable to Specify macOS min version
- Int Value is not accepting
- Support JSONPath
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cjson.