// Accepts NamespaceMapping instance that is no longer needed, storing // it for re-use. Note: do not pass null argument - this is not checked. internal void ReturnNSMapping(NamespaceMapping mapping) { mapping.next = freeNSMappings; freeNSMappings = mapping; }
// Accepts linked list of NamespaceMapping instances that is no longer needed, // storing them for re-use. Note: do not pass null argument - not checked. internal void ReturnNSMappingList(NamespaceMapping mapping) { NamespaceMapping lastMapping = mapping; // find last node while (lastMapping.next != null) lastMapping = lastMapping.next; lastMapping.next = freeNSMappings; freeNSMappings = mapping; }
// Returns NamespaceMapping instance properly initialized for new use, // re-using old instance if possible. internal NamespaceMapping NewNSMapping() { if (freeNSMappings == null) return new NamespaceMapping(); else { NamespaceMapping result = freeNSMappings; freeNSMappings = result.next; result.next = null; return result; } }
/// <summary>Prepares <see cref="ActiveMapping"/> instance for re-use, /// clearing stack.</summary> protected internal void Reset() { if (mappingsTop != null) { namespaces.ReturnNSMappingList(mappingsTop); mappingsTop = null; } }
/// <summary>Establishes a new mapping for the prefix associated with this /// instance, to an URI in a namespace scope, and pushes it on the stack.</summary> /// <param name="scope">Namespace scope the new mapping will be part of.</param> /// <param name="uri">URI to be mapped to this instance's prefix.</param> /// <returns>Newly added <see cref="NamespaceMapping"/>.</returns> protected internal NamespaceMapping PushMapping(string uri, NamespaceScope scope) { NamespaceMapping result = namespaces.NewNSMapping(); result.prefix = this; result.scope = scope; result.declared = uri != null; if (result.declared) result.uri = uri; else result.uri = this.Uri; result.next = mappingsTop; mappingsTop = result; return result; }
/// <summary>Discards most recently added <see cref="NamespaceMapping"/>, /// popping it from stack and returning it to the associated /// <see cref="XmlNamespaces"/> instance for re-use.</summary> protected internal void PopMapping() { NamespaceMapping nsMapping = mappingsTop; // protect against extra calls if (nsMapping == null) return; mappingsTop = nsMapping.next; namespaces.ReturnNSMapping(nsMapping); nsMapping.uri = null; // release uri }