Skip to content

Commit 1c46aae

Browse files
committed
Improved performance of debugging in ActiveScript modes
1 parent 8fd49fb commit 1c46aae

File tree

8 files changed

+98
-36
lines changed

8 files changed

+98
-36
lines changed

NuGet/MsieJavaScriptEngine.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine). Project was based on the code of SassAndCoffee.JavaScript (http://github.com/paulcbetts/SassAndCoffee), Chakra Sample Hosts (http://github.com/panopticoncentral/chakra-host) and jsrt-dotnet (http://github.com/robpaveza/jsrt-dotnet).</description>
1414
<summary>This library is a .NET wrapper for working with the JavaScript engines of Internet Explorer and Edge (JsRT versions of Chakra, ActiveScript version of Chakra and Classic JavaScript Engine).</summary>
15-
<releaseNotes>Changed a implementation of the `Dispose` method.</releaseNotes>
15+
<releaseNotes>Improved performance of debugging in ActiveScript modes.</releaseNotes>
1616
<copyright>Copyright (c) 2012-2018 Andrey Taritsyn - http://www.taritsyn.ru</copyright>
1717
<language>en-US</language>
1818
<tags>JavaScript ECMAScript MSIE IE Edge Chakra</tags>

NuGet/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
=============
2222
RELEASE NOTES
2323
=============
24-
Changed a implementation of the `Dispose` method.
24+
Improved performance of debugging in ActiveScript modes.
2525

2626
============
2727
PROJECT SITE

build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setlocal
44
set ORIGINAL_CURRENT_DIR=%cd%
55
set KOREBUILD_DOTNET_CHANNEL=rel-1.0.0
6-
set KOREBUILD_DOTNET_VERSION=1.1.7
6+
set KOREBUILD_DOTNET_VERSION=1.1.11
77

88
cd %~dp0
99

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
ORIGINAL_CURRENT_DIR=%cd%
33
KOREBUILD_DOTNET_CHANNEL=rel-1.0.0
4-
KOREBUILD_DOTNET_VERSION=1.1.7
4+
KOREBUILD_DOTNET_VERSION=1.1.11
55

66
repoFolder="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
77
cd $repoFolder

src/MsieJavaScriptEngine.Net4/MsieJavaScriptEngine.Net40.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@
312312
<Compile Include="..\MsieJavaScriptEngine\Helpers\NumericHelpers.cs">
313313
<Link>Helpers\NumericHelpers.cs</Link>
314314
</Compile>
315+
<Compile Include="..\MsieJavaScriptEngine\Helpers\TextHelpers.cs">
316+
<Link>Helpers\TextHelpers.cs</Link>
317+
</Compile>
315318
<Compile Include="..\MsieJavaScriptEngine\Helpers\TypeMappingHelpers.cs">
316319
<Link>Helpers\TypeMappingHelpers.cs</Link>
317320
</Compile>

src/MsieJavaScriptEngine/ActiveScript/Debugging/DebugDocument.cs

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Runtime.InteropServices;
6-
using System.Text.RegularExpressions;
6+
7+
using MsieJavaScriptEngine.Helpers;
78

89
namespace MsieJavaScriptEngine.ActiveScript.Debugging
910
{
@@ -13,11 +14,6 @@ namespace MsieJavaScriptEngine.ActiveScript.Debugging
1314
internal sealed class DebugDocument : IDebugDocumentInfo, IDebugDocumentProvider, IDebugDocument,
1415
IDebugDocumentText
1516
{
16-
/// <summary>
17-
/// Regular expression for working with a line break
18-
/// </summary>
19-
private static readonly Regex _lineBreakRegex = new Regex("\r\n|\n|\r");
20-
2117
/// <summary>
2218
/// Active Script wrapper
2319
/// </summary>
@@ -84,31 +80,6 @@ public DebugDocument(IActiveScriptWrapper activeScriptWrapper,
8480
}
8581

8682

87-
/// <summary>
88-
/// Finds a line break
89-
/// </summary>
90-
/// <param name="sourceCode">Source code</param>
91-
/// <param name="startPosition">Position in the input string that defines the leftmost
92-
/// position to be searched</param>
93-
/// <param name="length">Number of characters in the substring to include in the search</param>
94-
/// <param name="lineBreakPosition">Position of line break</param>
95-
/// <param name="lineBreakLength">Length of line break</param>
96-
private static void FindLineBreak(string sourceCode, int startPosition, int length,
97-
out int lineBreakPosition, out int lineBreakLength)
98-
{
99-
Match lineBreakMatch = _lineBreakRegex.Match(sourceCode, startPosition, length);
100-
if (lineBreakMatch.Success)
101-
{
102-
lineBreakPosition = lineBreakMatch.Index;
103-
lineBreakLength = lineBreakMatch.Length;
104-
}
105-
else
106-
{
107-
lineBreakPosition = -1;
108-
lineBreakLength = 0;
109-
}
110-
}
111-
11283
/// <summary>
11384
/// Initializes a debug document
11485
/// </summary>
@@ -126,7 +97,7 @@ private void Initialize()
12697
documentStartPosition : lineBreakPosition + lineBreakLength;
12798
int remainderLength = documentEndPosition - linePosition + 1;
12899

129-
FindLineBreak(_code, linePosition, remainderLength,
100+
TextHelpers.FindNextLineBreak(_code, linePosition, remainderLength,
130101
out lineBreakPosition, out lineBreakLength);
131102

132103
int lineLength = lineBreakPosition != -1 ? lineBreakPosition - linePosition : 0;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#if !NETSTANDARD1_3
2+
using MsieJavaScriptEngine.Utilities;
3+
4+
namespace MsieJavaScriptEngine.Helpers
5+
{
6+
/// <summary>
7+
/// Text helpers
8+
/// </summary>
9+
internal static class TextHelpers
10+
{
11+
/// <summary>
12+
/// Array of characters used to find the next line break
13+
/// </summary>
14+
private static readonly char[] _nextLineBreakChars = new char[] { '\r', '\n' };
15+
16+
17+
/// <summary>
18+
/// Finds a next line break
19+
/// </summary>
20+
/// <param name="sourceText">Source text</param>
21+
/// <param name="startPosition">Position in the input string that defines the leftmost
22+
/// position to be searched</param>
23+
/// <param name="length">Number of characters in the substring to include in the search</param>
24+
/// <param name="lineBreakPosition">Position of line break</param>
25+
/// <param name="lineBreakLength">Length of line break</param>
26+
public static void FindNextLineBreak(string sourceText, int startPosition, int length,
27+
out int lineBreakPosition, out int lineBreakLength)
28+
{
29+
lineBreakPosition = sourceText.IndexOfAny(_nextLineBreakChars, startPosition, length);
30+
if (lineBreakPosition != -1)
31+
{
32+
lineBreakLength = 1;
33+
char currentCharacter = sourceText[lineBreakPosition];
34+
35+
if (currentCharacter == '\r')
36+
{
37+
int nextCharacterPosition = lineBreakPosition + 1;
38+
char nextCharacter;
39+
40+
if (sourceText.TryGetChar(nextCharacterPosition, out nextCharacter)
41+
&& nextCharacter == '\n')
42+
{
43+
lineBreakLength = 2;
44+
}
45+
}
46+
}
47+
else
48+
{
49+
lineBreakLength = 0;
50+
}
51+
}
52+
}
53+
}
54+
#endif

src/MsieJavaScriptEngine/Utilities/StringExtensions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,39 @@ public static string CapitalizeFirstLetter(this string source)
100100

101101
return result;
102102
}
103+
104+
/// <summary>
105+
/// Gets a character at the specified index from the string.
106+
/// A return value indicates whether the receiving succeeded.
107+
/// </summary>
108+
/// <param name="source">The source string</param>
109+
/// <param name="index">The zero-based index of the character</param>
110+
/// <param name="result">When this method returns, contains the character from the string,
111+
/// if the receiving succeeded, or null character if the receiving failed.
112+
/// The receiving fails if the index out of bounds.</param>
113+
/// <returns>true if the character was received successfully; otherwise, false</returns>
114+
public static bool TryGetChar(this string source, int index, out char result)
115+
{
116+
if (source == null)
117+
{
118+
throw new ArgumentNullException("source");
119+
}
120+
121+
bool isSuccess;
122+
int length = source.Length;
123+
124+
if (length > 0 && index >= 0 && index < length)
125+
{
126+
result = source[index];
127+
isSuccess = true;
128+
}
129+
else
130+
{
131+
result = '\0';
132+
isSuccess = false;
133+
}
134+
135+
return isSuccess;
136+
}
103137
}
104138
}

0 commit comments

Comments
 (0)