-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1095 from lahma/improve-write-speed
Reduce string allocations when writing documents
- Loading branch information
Showing
28 changed files
with
290 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System.IO; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace NPOI.OpenXmlFormats; | ||
|
||
internal static class StreamWriterExtensions | ||
{ | ||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void WriteAttribute(this StreamWriter sw, string name, string value) | ||
{ | ||
sw.Write(" "); | ||
sw.Write(name); | ||
sw.Write("=\""); | ||
sw.Write(value); | ||
sw.Write("\""); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void WriteAttribute(this StreamWriter sw, string name, int value) | ||
{ | ||
sw.Write(" "); | ||
sw.Write(name); | ||
sw.Write("=\""); | ||
sw.Write(value); | ||
sw.Write("\""); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void WriteBooleanAttribute(this StreamWriter sw, string name, bool value) | ||
{ | ||
sw.Write(" "); | ||
sw.Write(name); | ||
sw.Write("=\""); | ||
sw.Write(value ? 1 : 0); | ||
sw.Write("\""); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void WriteElementAndContent(this StreamWriter sw, string name, string value) | ||
{ | ||
sw.Write("<"); | ||
sw.Write(name); | ||
sw.Write(">"); | ||
sw.Write(value); | ||
sw.Write("</"); | ||
sw.Write(name); | ||
sw.Write(">"); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void WriteEndElement(this StreamWriter sw, string name) | ||
{ | ||
sw.Write("</"); | ||
sw.Write(name); | ||
sw.Write(">"); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
public static void WriteEndW(this StreamWriter sw, string nodeName) | ||
{ | ||
sw.Write("</w:"); | ||
sw.Write(nodeName); | ||
sw.Write(">"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.