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

Remove slice cache that never had a hit and was of limited use #182

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
235 changes: 94 additions & 141 deletions Src/Common/Controls/DetailControls/DataTree.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,10 @@ public void CreateIndentedNodes_basic()

var path = GeneratePath();

var reuseMap = new ObjSeqHashMap();
// Data taken from a running Sena 3
var node = CreateXmlElementFromOuterXmlOf("<slice field=\"Form\" label=\"Form\" editor=\"multistring\" ws=\"all vernacular\" weight=\"light\" menu=\"mnuDataTree-LexemeForm\" contextMenu=\"mnuDataTree-LexemeFormContext\" spell=\"no\"><properties><bold value=\"on\" /><fontsize value=\"120%\" /></properties></slice>");

m_Slice.CreateIndentedNodes(caller, obj, indent, ref insPos, path, reuseMap, node);
m_Slice.CreateIndentedNodes(caller, obj, indent, ref insPos, path, node);
}

/// <remarks>
Expand Down Expand Up @@ -178,7 +177,6 @@ public void Collapse()
public void CreateGhostStringSlice_ParentSliceNotNull()
{
var path = GeneratePath();
var reuseMap = new ObjSeqHashMap();
var obj = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create();
m_DataTree = new DataTree();
m_Slice = GenerateSlice(Cache, m_DataTree);
Expand All @@ -190,7 +188,7 @@ public void CreateGhostStringSlice_ParentSliceNotNull()
int indent = 0;
int insertPosition = 0;
int flidEmptyProp = 5002031; // runtime flid of ghost field
m_DataTree.MakeGhostSlice(path, node, reuseMap, obj, m_Slice, flidEmptyProp, null, indent, ref insertPosition);
m_DataTree.MakeGhostSlice(path, node, obj, m_Slice, flidEmptyProp, null, indent, ref insertPosition);
var ghostSlice = m_DataTree.Slices[0];
Assert.NotNull(ghostSlice);
Assert.AreEqual(ghostSlice.PropTable, m_Slice.PropTable);
Expand Down
16 changes: 8 additions & 8 deletions Src/Common/Controls/DetailControls/Slice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ internal static int ExtraIndent(XmlNode indentNode)

/// <summary></summary>
public virtual void GenerateChildren(XmlNode node, XmlNode caller, ICmObject obj, int indent,
ref int insPos, ArrayList path, ObjSeqHashMap reuseMap, bool fUsePersistentExpansion)
ref int insPos, ArrayList path, bool fUsePersistentExpansion)
{
CheckDisposed();

Expand All @@ -1101,14 +1101,14 @@ public virtual void GenerateChildren(XmlNode node, XmlNode caller, ICmObject obj
if (indentNode != null)
{
// Similarly pretest for children of caller, to see whether anything is produced.
ContainingDataTree.ApplyLayout(obj, this, indentNode, indent + ExtraIndent(indentNode), insPos, path, reuseMap,
ContainingDataTree.ApplyLayout(obj, this, indentNode, indent + ExtraIndent(indentNode), insPos, path,
true, out ntr);
//fUseChildrenOfNode = false;
}
else
{
int insPosT = insPos; // don't modify the real one in this test call.
ntr = ContainingDataTree.ProcessPartChildren(node, path, reuseMap, obj, this, indent + ExtraIndent(node), ref insPosT,
ntr = ContainingDataTree.ProcessPartChildren(node, path, obj, this, indent + ExtraIndent(node), ref insPosT,
true, null, false, node);
//fUseChildrenOfNode = true;
}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ public virtual void GenerateChildren(XmlNode node, XmlNode caller, ICmObject obj
{
// Record the expansion state and generate the children.
Expansion = DataTree.TreeItemState.ktisExpanded;
CreateIndentedNodes(caller, obj, indent, ref insPos, path, reuseMap, node);
CreateIndentedNodes(caller, obj, indent, ref insPos, path, node);
}
else
{
Expand All @@ -1156,7 +1156,7 @@ public virtual void GenerateChildren(XmlNode node, XmlNode caller, ICmObject obj

/// <summary></summary>
public virtual void CreateIndentedNodes(XmlNode caller, ICmObject obj, int indent, ref int insPos,
ArrayList path, ObjSeqHashMap reuseMap, XmlNode node)
ArrayList path, XmlNode node)
{
CheckDisposed();

Expand All @@ -1170,10 +1170,10 @@ public virtual void CreateIndentedNodes(XmlNode caller, ICmObject obj, int inden
{
DataTree.NodeTestResult ntr;
insPos = ContainingDataTree.ApplyLayout(obj, this, indentNode, indent + ExtraIndent(indentNode),
insPos, path, reuseMap, false, out ntr);
insPos, path, false, out ntr);
}
else
ContainingDataTree.ProcessPartChildren(node, path, reuseMap, obj, this, indent + ExtraIndent(node), ref insPos,
ContainingDataTree.ProcessPartChildren(node, path, obj, this, indent + ExtraIndent(node), ref insPos,
false, parameter, false, caller);
}

Expand Down Expand Up @@ -1592,7 +1592,7 @@ public virtual void Expand(int iSlice)
if (Key.Length > 1)
caller = Key[Key.Length - 2] as XmlNode;
int insPos = iSlice + 1;
CreateIndentedNodes(caller, m_obj, Indent, ref insPos, new ArrayList(Key), new ObjSeqHashMap(), m_configurationNode);
CreateIndentedNodes(caller, m_obj, Indent, ref insPos, new ArrayList(Key), m_configurationNode);

Expansion = DataTree.TreeItemState.ktisExpanded;
if (m_propertyTable != null)
Expand Down
46 changes: 9 additions & 37 deletions Src/Common/Controls/DetailControls/SliceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ private static int GetWs(LcmCache cache, PropertyTable propertyTable, XmlNode no

/// <summary></summary>
public static Slice Create(LcmCache cache, string editor, int flid, XmlNode node, ICmObject obj,
IPersistenceProvider persistenceProvider, Mediator mediator, PropertyTable propertyTable, XmlNode caller, ObjSeqHashMap reuseMap)
IPersistenceProvider persistenceProvider, Mediator mediator, PropertyTable propertyTable, XmlNode caller)
{
Slice slice;
Slice slice = null;
switch(editor)
{
case "multistring": // first, these are the most common slices.
Expand Down Expand Up @@ -109,38 +109,17 @@ public static Slice Create(LcmCache cache, string editor, int flid, XmlNode node
}
case "defaultvectorreference": // second most common.
{
var rvSlice = reuseMap.GetSliceToReuse("ReferenceVectorSlice") as ReferenceVectorSlice;
if (rvSlice == null)
slice = new ReferenceVectorSlice(cache, obj, flid);
else
{
slice = rvSlice;
rvSlice.Reuse(obj, flid);
}
slice = new ReferenceVectorSlice(cache, obj, flid);
break;
}
case "possvectorreference":
{
var prvSlice = reuseMap.GetSliceToReuse("PossibilityReferenceVectorSlice") as PossibilityReferenceVectorSlice;
if (prvSlice == null)
slice = new PossibilityReferenceVectorSlice(cache, obj, flid);
else
{
slice = prvSlice;
prvSlice.Reuse(obj, flid);
}
slice = new PossibilityReferenceVectorSlice(cache, obj, flid);
break;
}
case "semdomvectorreference":
{
var prvSlice = reuseMap.GetSliceToReuse("SemanticDomainReferenceVectorSlice") as SemanticDomainReferenceVectorSlice;
if (prvSlice == null)
slice = new SemanticDomainReferenceVectorSlice(cache, obj, flid);
else
{
slice = prvSlice;
prvSlice.Reuse(obj, flid);
}
slice = new SemanticDomainReferenceVectorSlice(cache, obj, flid);
break;
}
case "string":
Expand Down Expand Up @@ -346,27 +325,20 @@ public static Slice Create(LcmCache cache, string editor, int flid, XmlNode node
break;
case "defaultvectorreferencedisabled": // second most common.
{
ReferenceVectorDisabledSlice rvSlice = reuseMap.GetSliceToReuse("ReferenceVectorDisabledSlice") as ReferenceVectorDisabledSlice;
if (rvSlice == null)
slice = new ReferenceVectorDisabledSlice(cache, obj, flid);
else
{
slice = rvSlice;
rvSlice.Reuse(obj, flid);
}
slice = new ReferenceVectorDisabledSlice(cache, obj, flid);
break;
}
default:
{
//Since the editor has not been implemented yet,
//is there a bitmap file that we can show for this editor?
//Such bitmaps belong in the distFiles xde directory
string fwCodeDir = FwDirectoryFinder.CodeDirectory;
string editorBitmapRelativePath = "xde/" + editor + ".bmp";
var fwCodeDir = FwDirectoryFinder.CodeDirectory;
var editorBitmapRelativePath = "xde/" + editor + ".bmp";
if(File.Exists(Path.Combine(fwCodeDir, editorBitmapRelativePath)))
slice = new ImageSlice(fwCodeDir, editorBitmapRelativePath);
else
slice = new MessageSlice(String.Format(DetailControlsStrings.ksBadEditorType, editor));
slice = new MessageSlice(string.Format(DetailControlsStrings.ksBadEditorType, editor));
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions Src/LexText/Lexicon/LexReferenceMultiSlice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void SetRefs()
}

public override void GenerateChildren(XmlNode node, XmlNode caller, ICmObject obj, int indent,
ref int insPos, ArrayList path, ObjSeqHashMap reuseMap, bool fUsePersistentExpansion)
ref int insPos, ArrayList path, bool fUsePersistentExpansion)
{
CheckDisposed();
// If node has children, figure what to do with them...
Expand All @@ -150,14 +150,14 @@ public override void GenerateChildren(XmlNode node, XmlNode caller, ICmObject ob

for (int i = 0; i < m_refs.Count; i++)
{
GenerateChildNode(i, node, caller, indent, ref insPos, path, reuseMap);
GenerateChildNode(i, node, caller, indent, ref insPos, path);
}

Expansion = DataTree.TreeItemState.ktisExpanded;
}

private void GenerateChildNode(int iChild, XmlNode node, XmlNode caller, int indent,
ref int insPos, ArrayList path, ObjSeqHashMap reuseMap)
ref int insPos, ArrayList path)
{
var lr = m_refs[iChild];
var lrt = lr.Owner as ILexRefType;
Expand Down Expand Up @@ -301,7 +301,7 @@ private void GenerateChildNode(int iChild, XmlNode node, XmlNode caller, int ind
" menu=\"" + sMenu + "\"><deParams displayProperty=\"HeadWord\"/></slice>";
node.InnerXml = sXml;
int firstNewSliceIndex = insPos;
CreateIndentedNodes(caller, lr, indent, ref insPos, path, reuseMap, node);
CreateIndentedNodes(caller, lr, indent, ref insPos, path, node);
for (int islice = firstNewSliceIndex; islice < insPos; islice++)
{
Slice child = ContainingDataTree.Slices[islice] as Slice;
Expand Down Expand Up @@ -769,7 +769,7 @@ protected void ExpandNewNode()
caller = Key[Key.Length - 2] as XmlNode;
int insPos = this.IndexInContainer + m_refs.Count;
GenerateChildNode(m_refs.Count-1, m_configurationNode, caller, Indent,
ref insPos, new ArrayList(Key), new ObjSeqHashMap());
ref insPos, new ArrayList(Key));
Expansion = DataTree.TreeItemState.ktisExpanded;
}
finally
Expand All @@ -795,7 +795,7 @@ public override void Expand(int iSlice)
if (Key.Length > 1)
caller = Key[Key.Length - 2] as XmlNode;
int insPos = iSlice + 1;
GenerateChildren(m_configurationNode, caller, m_obj, Indent, ref insPos, new ArrayList(Key), new ObjSeqHashMap(), false);
GenerateChildren(m_configurationNode, caller, m_obj, Indent, ref insPos, new ArrayList(Key), false);
Expansion = DataTree.TreeItemState.ktisExpanded;
}
finally
Expand Down
14 changes: 7 additions & 7 deletions Src/LexText/Lexicon/RoledParticipantsSlice.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015 SIL International
// Copyright (c) 2015 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)

Expand Down Expand Up @@ -104,20 +104,20 @@ protected override void InitLauncher()
}

public override void GenerateChildren(XmlNode node, XmlNode caller, ICmObject obj, int indent, ref int insPos,
ArrayList path, ObjSeqHashMap reuseMap, bool fUsePersistentExpansion)
ArrayList path, bool fUsePersistentExpansion)
{
CheckDisposed();

foreach (IRnRoledPartic roledPartic in Record.ParticipantsOC)
{
if (roledPartic.RoleRA != null)
GenerateChildNode(roledPartic, node, caller, indent, ref insPos, path, reuseMap);
GenerateChildNode(roledPartic, node, caller, indent, ref insPos, path);
}
Expansion = Record.ParticipantsOC.Count == 0 ? DataTree.TreeItemState.ktisCollapsedEmpty : DataTree.TreeItemState.ktisExpanded;
}

private void GenerateChildNode(IRnRoledPartic roledPartic, XmlNode node, XmlNode caller, int indent,
ref int insPos, ArrayList path, ObjSeqHashMap reuseMap)
ref int insPos, ArrayList path)
{
var sliceElem = new XElement("slice",
new XAttribute("label", roledPartic.RoleRA.Name.BestAnalysisAlternative.Text),
Expand All @@ -130,7 +130,7 @@ private void GenerateChildNode(IRnRoledPartic roledPartic, XmlNode node, XmlNode
sliceElem.Add(XElement.Parse(childNode.OuterXml));
}
node.InnerXml = sliceElem.ToString();
CreateIndentedNodes(caller, roledPartic, indent, ref insPos, path, reuseMap, node);
CreateIndentedNodes(caller, roledPartic, indent, ref insPos, path, node);
node.InnerXml = "";
}

Expand Down Expand Up @@ -355,7 +355,7 @@ private void ExpandNewNode(IRnRoledPartic roledPartic)
if (Key.Length > 1)
caller = Key[Key.Length - 2] as XmlNode;
int insPos = IndexInContainer + Record.ParticipantsOC.Count - 1;
GenerateChildNode(roledPartic, m_configurationNode, caller, Indent, ref insPos, new ArrayList(Key), new ObjSeqHashMap());
GenerateChildNode(roledPartic, m_configurationNode, caller, Indent, ref insPos, new ArrayList(Key));
Expansion = DataTree.TreeItemState.ktisExpanded;
}
finally
Expand All @@ -379,7 +379,7 @@ public override void Expand(int iSlice)
if (Key.Length > 1)
caller = Key[Key.Length - 2] as XmlNode;
int insPos = iSlice + 1;
GenerateChildren(m_configurationNode, caller, m_obj, Indent, ref insPos, new ArrayList(Key), new ObjSeqHashMap(), false);
GenerateChildren(m_configurationNode, caller, m_obj, Indent, ref insPos, new ArrayList(Key), false);
Expansion = DataTree.TreeItemState.ktisExpanded;
}
finally
Expand Down
Loading