Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e7be304

Browse files
committed
Remove lazy initialization in raw errno -> Error conversion
It turns out that every place we get an ErrorInfo from a raw errno, we access the PAL Error almost immediately. The lazy initialization carried a risk that copies of an ErrorInfo with the conversion deferred would get passed around and cause the conversion to happen more than once. Also, there was an unnecessary branch when accessing the Error. The lazy initialization in the reverse Error -> raw errno case is left intact because it is common to create an ErrorInfo from an Error to pass to a caller that needs an ErrorInfo, but doesn't always need the raw errno.
1 parent e82401b commit e7be304

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Common/src/Interop/Unix/Interop.Errors.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ internal struct ErrorInfo
115115

116116
internal ErrorInfo(int errno)
117117
{
118-
_error = (Error)(-1);
118+
_error = Interop.Sys.ConvertErrorPlatformToPal(errno);
119119
_rawErrno = errno;
120120
}
121121

@@ -127,7 +127,7 @@ internal ErrorInfo(Error error)
127127

128128
internal Error Error
129129
{
130-
get { return _error == (Error)(-1) ? (_error = Interop.Sys.ConvertErrorPlatformToPal(_rawErrno)) : _error; }
130+
get { return _error; }
131131
}
132132

133133
internal int RawErrno

0 commit comments

Comments
 (0)