-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
implement box avoidance #2639
implement box avoidance #2639
Conversation
@JamesNK nits resolved |
Does this have any impact on comparisons when the value is still boxed? I wonder about people doing something dumb like: if (JValue1.Value == JValue2.Value)
{
} Before it would be false but now it is true (if values are -1 to 8 and share a box) |
@JamesNK yes, technically the change is observable; however, the code as shown is already incorrect for most definitions of "correct"/"incorrect"; when dealing with if (Equals(JValue1.Value, JValue2.Value))
{
} or if (JValue1.Value.Equals(JValue2.Value))
{
} The [Test]
public void EmptyStringsAreSame()
{
var obj = (JObject)JToken.Parse(@"{""x"": """", ""y"": """"}");
var x = ((JValue)obj["x"]).Value;
var y = ((JValue)obj["y"]).Value;
Assert.AreSame(x, y);
Assert.AreEqual(x, y);
Assert.IsTrue(x == y);
}
[Test]
public void EqualStringsAreNotSame()
{
var obj = (JObject)JToken.Parse(@"{""x"": ""a"", ""y"": ""a""}");
var x = ((JValue)obj["x"]).Value;
var y = ((JValue)obj["y"]).Value;
Assert.AreNotSame(x, y);
Assert.AreEqual(x, y);
Assert.IsFalse(x == y);
} I'm not sure we should be too concerned about obviously-broken code. |
…, select and justify handling range
Thanks @mgravell |
This reverts commit 13717cf. # Conflicts: # Src/Newtonsoft.Json/Utilities/BoxedPrimitives.cs
Co-authored-by: Marc Gravell <[email protected]> Co-authored-by: James Newton-King <[email protected]>
fix #2638
BoxedPrimitives
helper that holds boxed instances for common primitive values and has helper APIsBoxedPrimitives
in preference to vanilla boxing inJValue
andJsonTextReader
new JValue(object)
in key pathsDisclosure: if someone uses
Unsafe
methods to mutate the inside of one of these boxes: bad things. But that is self-inflicted.