-
Notifications
You must be signed in to change notification settings - Fork 40
Fix config.Root calculation #199
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
Fix config.Root calculation #199
Conversation
Ideally we should have all HOCON inner structures immutable, because all of this bugs are coming because entities reference each other and can modify each other, making it quite messy to debug. That nice moment, when the value is changed because of you just viewed it in your debugger... But this is much more major task then fixing |
Since #198 turned out to be a mistake, rolled back it's changes. Now should be just fine. |
|
||
// If Fallback is not set - we will set it in new copy | ||
// If Fallback was set - just use it, but with adding new fallback values | ||
return new Config((HoconValue) Value.Clone(null), Fallback?.WithFallback(fallback) ?? fallback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turned out to be much more elegant solution for getting new config with fallback, and without internal state mutations.
return aggregated; | ||
} | ||
} | ||
public virtual HoconValue Root { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is where we will safe on allocations. Root
is immutable and calculated only once, in constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -54,27 +66,12 @@ public Config(HoconRoot root) : base(root?.Value, root?.Substitutions ?? Enumera | |||
/// <summary> | |||
/// The configuration used as a secondary source. | |||
/// </summary> | |||
public Config Fallback { get; private set; } | |||
public Config Fallback { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fallback should never change. It is either set, or not set for given config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing improvements here. Nice work.
@@ -54,27 +66,12 @@ public Config(HoconRoot root) : base(root?.Value, root?.Substitutions ?? Enumera | |||
/// <summary> | |||
/// The configuration used as a secondary source. | |||
/// </summary> | |||
public Config Fallback { get; private set; } | |||
public Config Fallback { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea.
return aggregated; | ||
} | ||
} | ||
public virtual HoconValue Root { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
/// <summary> | ||
/// Performs aggregation of Value and all Fallbacks into single <see cref="HoconValue"/> object | ||
/// </summary> | ||
private HoconValue GetRootValue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm much happier with this now that it's only run once.
Close #195
@Aaronontheweb This is based on #197 , so may be better to review/merge that one first.
The main improvement here is not only the fact that
Root
is not calculated on config creation - alsoConfig
instance now is not modified due to any private methods after is created with constructor.Before there were some private setters, that were making harder to with
Config
as with immutable data structure. Now it is refactored to be fully built on constructor invocation, and we are safe to write code in this class without breaking immutability (of cause if we will not touch property setters).