YACYAML icon indicating copy to clipboard operation
YACYAML copied to clipboard

Disable anchor/alias completely

Open neolee opened this issue 12 years ago • 2 comments

YACYAML is amazing YAML parser/omitter for Objective-C! The only concern I have now is the automatic Anchor/Alias mechanism. In some of my cases I want to completely disable this feature, any chance?

neolee avatar Feb 07 '13 09:02 neolee

As I guess you've found, it's possible to disable anchors for scalers (in fact it's the default - the "YACYAMLKeyedArchiverOptionAllowScalarAnchors" flag turns on anchor emission for scalars).

With arbitrary objects, the problem is that the emitter would infinite-loop if there were any cycles in the object graph, emitting an infinite amount of increasingly nested data as it keeps following the cycle infinitely.

If your concern is the cost of all the hashing and potential comparisons (to find out if every emitted object is equal to an already emitted one), you can turn on "YACYAMLKeyedArchiverOptionDontUseObjectEquality" and then the emitter will only emit anchors for objects that are the /same/ object as one seen before (i.e. at the same address in memory), rather than if they're 'isEqual:'-equal to an object that's been seen before.

Having said all that, if you have a real need for this, I would not be opposed to a "YACYAMLKeyedArchiverOptionDontEmitAnchors" option (with the caveat that it might infinite loop and produce endless output if used incorrectly, as mentioned above).

th-in-gs avatar Feb 07 '13 10:02 th-in-gs

Thanks a lot for your rapidly and nicely written feedback. My concern is the readability. I am working on some configuration files of third party system. Consider the following data structure:

applications: app1: config1: true config2: true app2: config1: true config2: true ......

Applying anchor/alias on these data will sacrifice the overall readability in my opinion. So if possible an option disable alias completely I will very be appreciated. Thanks again for rely.

On Thursday, February 7, 2013, James Montgomerie wrote:

As I guess you've found, it's possible to disable anchors for scalers (in fact it's the default - the "YACYAMLKeyedArchiverOptionAllowScalarAnchors" flag turns on anchor emission for scalars).

With arbitrary objects, the problem is that the emitter would infinite-loop if there were any cycles in the object graph, emitting an infinite amount of increasingly nested data ad it keeps following the cycle infinitely.

If your concern is the cost of all the hashing and potential comparisons (to find out if every emitted object is equal to an already emitted one), you can turn on "YACYAMLKeyedArchiverOptionDontUseObjectEquality" and then the emitter will only emit anchors for objects that are the /same/ object as one seen before (i.e. at the same address in memory), rather than if they're 'isEqual:'-equal to an object that's been seen before.

Having said all that, if you have a real need for this, I would not be opposed to a "YACYAMLKeyedArchiverOptionDontEmitAnchors" option (with the caveat that it might infinite loop and produce endless output if used incorrectly, as mentioned above).

— Reply to this email directly or view it on GitHubhttps://github.com/th-in-gs/YACYAML/issues/3#issuecomment-13229526.

No, I will not fix your computer!

[email protected]

neolee avatar Feb 07 '13 10:02 neolee