Skip to content

Commit

Permalink
minor improvements of runtime efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
Viir committed Jan 2, 2025
1 parent 05c00ec commit 6b938dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
31 changes: 31 additions & 0 deletions implement/Pine.Core/PopularValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,37 @@ from c2 in Enumerable.Range(0, 128)
"Leaf",
"Branch2",

"module",
"exposing",
"import",
"as",
"if",
"then",
"else",
"let",
"in",
"case",
"of",
"type",
"alias",
"port",
"infix",
"infixl",
"infixr",
"where",

"Problem",
"ExpectingNumber",
"ExpectingSymbol",
"ExpectingAnyChar",
"ExpectingKeyword",
"ExpectingCharSatisfyingPredicate",
"ExpectingStringSatisfyingPredicate",
"ExpectingCustom",
"ExpectingOneOf",



// module LanguageService

"LanguageService",
Expand Down
23 changes: 12 additions & 11 deletions implement/pine/Pine/PineVM/PineVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,21 +2403,22 @@ public static PineValue ValueFromPathInValueOrEmptyList(
PineValue environment,
ReadOnlySpan<int> path)
{
if (path.Length is 0)
return environment;
var currentNode = environment;

if (environment is not PineValue.ListValue listValue)
return PineValue.EmptyList;
for (var i = 0; i < path.Length; i++)
{
if (currentNode is not PineValue.ListValue listValue)
return PineValue.EmptyList;

var skipCount = path[0];
var skipCount = path[i];

if (path[0] >= listValue.Elements.Count)
return PineValue.EmptyList;
if (skipCount >= listValue.Elements.Count)
return PineValue.EmptyList;

return
ValueFromPathInValueOrEmptyList(
listValue.Elements[skipCount < 0 ? 0 : skipCount],
path[1..]);
currentNode = listValue.Elements[skipCount < 0 ? 0 : skipCount];
}

return currentNode;
}

public PineValue EvaluateConditionalExpression(
Expand Down

0 comments on commit 6b938dc

Please sign in to comment.