Skip to content

DateTime.TryParse allocates on some failure paths #90907

@stephentoub

Description

@stephentoub

Various code paths end up allocating as part of calling DateTimeResult.SetFailure(ParseFailureKind, object), boxing a value type second argument. For DateTime.Parse, this is reasonable, given we're about to throw an exception. But for TryParse, it should still be as cheap as possible even on failure to parse; it's often used as part of multiple checks to determine the format of a given piece of data, so failure to parse still happens on hot / success paths (e.g. after checking whether it's a DateTime and determining it's not, it might successfully parse as something else).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions