Table of Contents

Class InterningProvider

Namespace
ICSharpCode.Decompiler.TypeSystem
Assembly
ICSharpCode.Decompiler.dll

Provider used for interning.

public abstract class InterningProvider
Inheritance
InterningProvider
Inherited Members

Remarks

A simple IInterningProvider implementation could use 3 dictionaries:

  1. using value equality comparer (for certain types known to implement value equality, e.g. string and IType)
  2. using comparer that calls into ISupportsInterning (for types implementing ISupportsInterning)
  3. list comparer (for InternList method)

On the first Intern()-call, the provider tells the object to prepare for interning (ISupportsInterning.PrepareForInterning) and stores it into a dictionary. On further Intern() calls, the original object is returned for all equal objects. This allows reducing the memory usage by using a single object instance where possible.

Interning provider implementations could also use the interning logic for different purposes: for example, it could be used to determine which objects are used jointly between multiple type definitions and which are used only within a single type definition. Then a persistent file format could be organized so that shared objects are loaded only once, yet non-shared objects get loaded lazily together with the class.

Constructors

InterningProvider()

protected InterningProvider()

Fields

Dummy

public static readonly InterningProvider Dummy

Field Value

InterningProvider

Methods

Intern(ISupportsInterning?)

Interns the specified object.

If the object is freezable, it will be frozen.

public abstract ISupportsInterning? Intern(ISupportsInterning? obj)

Parameters

obj ISupportsInterning

Returns

ISupportsInterning

Intern(string?)

Interns the specified string.

public abstract string? Intern(string? text)

Parameters

text string

Returns

string

InternList<T>(IList<T>?)

Interns the given list. Uses reference equality to compare the list elements.

public abstract IList<T>? InternList<T>(IList<T>? list) where T : class

Parameters

list IList<T>

Returns

IList<T>

Type Parameters

T

InternValue(object?)

Inters a boxed value type.

public abstract object? InternValue(object? obj)

Parameters

obj object

Returns

object

Intern<T>(T?)

Interns the specified object.

If the object is freezable, it will be frozen.

public T? Intern<T>(T? obj) where T : class, ISupportsInterning

Parameters

obj T

Returns

T

Type Parameters

T