@@ -24,7 +24,7 @@ public sealed partial class RazorCodeDocument
24
24
public RazorFileKind FileKind => ParserOptions . FileKind ;
25
25
26
26
private readonly PropertyTable _properties = new ( ) ;
27
- private readonly object _htmlDocumentLock = new ( ) ;
27
+ private readonly Lazy < RazorHtmlDocument > _lazyHtmlDocument ;
28
28
29
29
private RazorCodeDocument (
30
30
RazorSourceDocument source ,
@@ -40,6 +40,7 @@ private RazorCodeDocument(
40
40
CodeGenerationOptions = codeGenerationOptions ?? RazorCodeGenerationOptions . Default ;
41
41
42
42
_properties = properties ?? new ( ) ;
43
+ _lazyHtmlDocument = new ( ( ) => CreateHtmlDocument ( ) ) ;
43
44
}
44
45
45
46
public static RazorCodeDocument Create (
@@ -177,20 +178,17 @@ internal void SetCSharpDocument(RazorCSharpDocument value)
177
178
}
178
179
179
180
internal RazorHtmlDocument GetHtmlDocument ( )
181
+ => _lazyHtmlDocument . Value ;
182
+
183
+ private RazorHtmlDocument CreateHtmlDocument ( )
180
184
{
181
185
if ( _properties . HtmlDocument . TryGetValue ( out var result ) )
182
186
{
183
187
return result ;
184
188
}
185
189
186
- lock ( _htmlDocumentLock )
187
- {
188
- if ( ! _properties . HtmlDocument . TryGetValue ( out result ) )
189
- {
190
- result = RazorHtmlWriter . GetHtmlDocument ( this ) ;
191
- _properties . HtmlDocument . SetValue ( result ) ;
192
- }
193
- }
190
+ result = RazorHtmlWriter . GetHtmlDocument ( this ) ;
191
+ _properties . HtmlDocument . SetValue ( result ) ;
194
192
195
193
return result ;
196
194
}
0 commit comments