Skip to content

Commit 7915749

Browse files
authored
Merge pull request #121 from udlose/performance/reduce-allocations
Fix #116 and Performance/reduce allocations
2 parents 64a7a5e + 50acd6b commit 7915749

File tree

24 files changed

+10658
-298
lines changed

24 files changed

+10658
-298
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33
##
4-
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
4+
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
55

66
# User-specific files
77
*.rsuser
@@ -43,6 +43,9 @@ Generated\ Files/
4343
[Tt]est[Rr]esult*/
4444
[Bb]uild[Ll]og.*
4545

46+
# VisualStudio live unit testing
47+
*.lutconfig
48+
4649
# NUnit
4750
*.VisualState.xml
4851
TestResult.xml

src/TextMateSharp.Grammars/Resources/ResourceLoader.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.IO;
1+
using System.IO;
32
using System.Reflection;
43

54
namespace TextMateSharp.Grammars.Resources
@@ -12,7 +11,7 @@ internal class ResourceLoader
1211

1312
internal static Stream OpenGrammarPackage(string grammarName)
1413
{
15-
string grammarPackage = GrammarPrefix + grammarName.ToLowerInvariant() + "." + "package.json";
14+
string grammarPackage = GrammarPrefix + grammarName.ToLowerInvariant() + ".package.json";
1615

1716
var result = typeof(ResourceLoader).GetTypeInfo().Assembly.GetManifestResourceStream(
1817
grammarPackage);

src/TextMateSharp.Tests/Grammar/LineTextTests.cs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
using System;
2-
31
using NUnit.Framework;
4-
2+
using System;
53
using TextMateSharp.Grammars;
64

75
namespace TextMateSharp.Tests.Grammar
@@ -351,15 +349,6 @@ public void GetHashCode_SameContent_ShouldReturnSameHash()
351349
Assert.AreEqual(lineText1.GetHashCode(), lineText2.GetHashCode());
352350
}
353351

354-
[Test]
355-
public void GetHashCode_DifferentContent_ShouldReturnDifferentHash()
356-
{
357-
LineText lineText1 = "hello";
358-
LineText lineText2 = "world";
359-
360-
Assert.AreNotEqual(lineText1.GetHashCode(), lineText2.GetHashCode());
361-
}
362-
363352
[Test]
364353
public void GetHashCode_EmptyLineText_ShouldReturnZero()
365354
{
@@ -390,10 +379,12 @@ public void GetHashCode_SameInstance_ShouldBeConsistent()
390379
}
391380

392381
[Test]
393-
public void GetHashCode_DifferentArraysSameContent_ShouldReturnSameHash()
382+
public void GetHashCode_DifferentStringInstances_SameContent_ShouldReturnSameHash()
394383
{
384+
// avoid declaring these as const and use this pattern to dodge string interning
385+
// which would make them reference the same object and not test the content-based hash code properly
395386
string buffer1 = "hello";
396-
string buffer2 = "hello";
387+
string buffer2 = new string("hello".ToCharArray());
397388

398389
LineText lineText1 = buffer1.AsMemory();
399390
LineText lineText2 = buffer2.AsMemory();
@@ -423,27 +414,12 @@ public void GetHashCode_UnicodeContent_ShouldWork()
423414
}
424415

425416
[Test]
426-
public void GetHashCode_SimilarStrings_ShouldProduceDifferentHashes()
427-
{
428-
// These are similar but should have different hashes
429-
LineText lineText1 = "abc";
430-
LineText lineText2 = "abd";
431-
LineText lineText3 = "bbc";
432-
433-
Assert.AreNotEqual(lineText1.GetHashCode(), lineText2.GetHashCode());
434-
Assert.AreNotEqual(lineText1.GetHashCode(), lineText3.GetHashCode());
435-
Assert.AreNotEqual(lineText2.GetHashCode(), lineText3.GetHashCode());
436-
}
437-
438-
[Test]
439-
public void GetHashCode_SingleCharacter_ShouldWork()
417+
public void GetHashCode_SingleCharacter_WithSameContent_ShouldWork()
440418
{
441419
LineText lineText1 = "a";
442420
LineText lineText2 = "a";
443-
LineText lineText3 = "b";
444421

445422
Assert.AreEqual(lineText1.GetHashCode(), lineText2.GetHashCode());
446-
Assert.AreNotEqual(lineText1.GetHashCode(), lineText3.GetHashCode());
447423
}
448424

449425
#endregion

0 commit comments

Comments
 (0)