Skip to content
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

Fixes #1472. Optimize CT_Row.Copy to reduce row cloning time under 1ms #1473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions OpenXmlFormats/Wordprocessing/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5521,6 +5521,10 @@ public class CT_Row
private byte[] paraIdField;
private byte[] textIdField;

public XmlNode XmlNode { get; private set; }

public XmlNamespaceManager NamespaceManager { get; private set; }

public CT_Row()
{
this.itemsElementNameField = new List<ItemsChoiceTableRowType>();
Expand All @@ -5537,6 +5541,8 @@ public static CT_Row Parse(XmlNode node, XmlNamespaceManager namespaceManager, o
if (node == null)
return null;
CT_Row ctObj = new CT_Row();
ctObj.XmlNode = node;
ctObj.NamespaceManager = namespaceManager;
if (parent != null)
ctObj.parent = parent;
if (node.Attributes["w14:paraId"] != null)
Expand Down Expand Up @@ -5775,18 +5781,7 @@ internal void Write(StreamWriter sw, string nodeName)
}
public CT_Row Copy()
{
CT_Row ctRow = new CT_Row();
ctRow.paraIdField = this.paraIdField?.ToArray();
ctRow.rsidRField = this.rsidRField?.ToArray();
ctRow.rsidDelField = this.rsidDelField?.ToArray();
ctRow.rsidRPrField = this.rsidRPrField?.ToArray();
ctRow.rsidTrField = this.rsidTrField?.ToArray();
ctRow.textIdField = this.textIdField?.ToArray();
ctRow.trPrField = this.trPrField?.Copy();
ctRow.tblPrExField = this.tblPrExField?.Copy();
ctRow.itemsElementNameField = this.itemsElementNameField?.Copy();
ctRow.itemsField = this.itemsField?.Copy();
return ctRow;
return Parse(XmlNode, NamespaceManager, Parent);
}
public void RemoveTc(int pos)
{
Expand Down
10 changes: 10 additions & 0 deletions ooxml/XWPF/Usermodel/XWPFTableRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ public XWPFTableRow CloneRow()
return clonedRow;
}

/**
* Clones a table row and inserts it at the specified position in the table
*/
public XWPFTableRow CloneRow(int pos)
{
XWPFTableRow clonedRow= new XWPFTableRow(ctRow.Copy(), this.table);
table.AddRow(clonedRow, pos);
return clonedRow;
}

/**
* This element specifies the height of the current table row within the
* current table. This height shall be used to determine the resulting
Expand Down
Loading