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

optimize token channels management #433

Merged
merged 1 commit into from
Apr 17, 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
Binary file added baseline.dtp
Binary file not shown.
3 changes: 3 additions & 0 deletions baseline.dtp.State
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/SnapshotState/CallTreeHistoryV3/@EntryValue">[{"CurrentPrefix":{"Path":{"Items":[{"Fuid":5,"IsLogicalRoot":true}]}},"BacktraceSelection":{"Path":[]},"DowntraceSelection":{"Path":[{"Fuid":7,"IsLogicalRoot":true},{"Fuid":2305843009215791107,"MergeType":2},{"Fuid":2305843009218936880},{"Fuid":2305843009218936881},{"Fuid":2305843009218937558},{"Fuid":2305843009218937559},{"Fuid":2305843009218937664},{"Fuid":2305843009218937665},{"Fuid":2305843009218937750},{"Fuid":2305843009218937756}]},"GroupedByThreadBacktraceSelection":{"Path":[]},"GroupedByThreadDowntraceSelection":{"Path":[]}}]</s:String>
<s:String x:Key="/Default/SnapshotState/CallTreeVisualState/@EntryValue">{"Root":{"Key":{},"Children":[{"$id":"1","Key":{"Fuid":{"Value":7}},"Value":{},"Children":[{"$id":"2","Key":{"Fuid":{"Value":2305843009215791107},"MergeType":2},"Value":{},"Children":[{"$id":"3","Key":{"Fuid":{"Value":2305843009218936880}},"Value":{"ChangedState":2,"Values":2},"Children":[{"$id":"4","Key":{"Fuid":{"Value":2305843009218936881}},"Value":{},"Children":[{"$id":"5","Key":{"Fuid":{"Value":2305843009218936882}},"Value":{"ChangedState":2,"Values":2}},{"$id":"6","Key":{"Fuid":{"Value":2305843009218937558}},"Value":{"ChangedState":2,"Values":2},"Children":[{"$id":"7","Key":{"Fuid":{"Value":2305843009218937559}},"Value":{},"Children":[{"$id":"8","Key":{"Fuid":{"Value":2305843009218937664}},"Value":{"ChangedState":2,"Values":2}}]}]}]}]}]}]}]}}</s:String></wpf:ResourceDictionary>
Binary file added mx.dtp
Binary file not shown.
Binary file added precompute.dtp
Binary file not shown.
1 change: 1 addition & 0 deletions src/sly/lexer/LexerResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public LexerResult(List<Token<IN>> tokens)
public void SetTokens(List<Token<IN>> tokens)
{
Tokens = new TokenChannels<IN>(tokens);
Tokens.PreCompute();
}

public LexerResult(LexicalError error, List<Token<IN>> tokens)
Expand Down
8 changes: 6 additions & 2 deletions src/sly/lexer/TokenChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ private void SetToken(int i, Token<IN> token)
}
}
Tokens[i] = token;
_notNullTokens = Tokens.Where(x => x != null).ToList();
_notNullOrEosTokens = Tokens.Where(x => x != null && !x.IsEOS).ToList();
}

public Token<IN> this[int key]
Expand Down Expand Up @@ -77,5 +75,11 @@ public override string ToString()
}
return builder.ToString();
}

public void PreCompute()
{
_notNullTokens = Tokens.Where(x => x != null).ToList();
_notNullOrEosTokens = Tokens.Where(x => x != null && !x.IsEOS).ToList();
}
}
}
16 changes: 14 additions & 2 deletions src/sly/lexer/TokenChannels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ public void Add(Token<IN> token)
{
token.TokenChannels = this;
TokenChannel<IN> channel = null;
var mx = _tokenChannels?.Values != null && _tokenChannels.Values.Any() ? _tokenChannels.Values.Max(x => x.Count) : 0;

if (!TryGet(token.Channel, out channel))
{


channel = new TokenChannel<IN>(token.Channel);
int shift = 0;
if (_tokenChannels.Values.Any())
{
shift = _tokenChannels.Values.Max(x => x.Count);
shift = mx;
}
for (int i = 0; i < shift; i++)
{
Expand All @@ -82,7 +86,7 @@ public void Add(Token<IN> token)
_tokenChannels[token.Channel] = channel;
}

int index = _tokenChannels.Values.Max(x => x.Count);
int index = mx;
foreach (var VARIABLE in _tokenChannels.Values)
{
for (int i = channel.Count; i < index; i++)
Expand Down Expand Up @@ -116,5 +120,13 @@ public override string ToString()
{
return string.Join("\n", _tokenChannels.Values.Select(x => x.ToString()).ToArray());
}

public void PreCompute()
{
foreach (var channel in _tokenChannels)
{
channel.Value.PreCompute();
}
}
}
}
Loading