Skip to content

Commit

Permalink
Merge pull request #13 from danipen/sync-create-regex
Browse files Browse the repository at this point in the history
Sync create oniguruma regex
  • Loading branch information
danipen authored Feb 18, 2022
2 parents 5784411 + 17d9a8a commit bd074b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,7 @@ onigwrap/src/libonigwrap.so
.idea/.idea.TextMateSharp.dir/.idea/encodings.xml
.idea/.idea.TextMateSharp.dir/.idea/indexLayout.xml
.idea/.idea.TextMateSharp.dir/.idea/vcs.xml
onigwrap/src/onigwrap.lib
onigwrap/src/onigwrap.exp
onigwrap/src/onigwrap.dll
onigwrap/src/onig_s.lib
17 changes: 11 additions & 6 deletions src/TextMateSharp/Internal/Oniguruma/ORegex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace TextMateSharp.Internal.Oniguruma
{
public class ORegex : IDisposable
{
private static object _createRegexSync = new object();

private IntPtr _regex;
private IntPtr _region;
private bool _disposed = false;
Expand All @@ -28,13 +30,16 @@ public unsafe ORegex(string pattern, bool ignoreCase = true, bool multiline = fa
pattern = UnicodeCharEscape.AddBracesToUnicodePatterns(pattern);
pattern = UnicodeCharEscape.ConstraintUnicodePatternLenght(pattern);

fixed (char* patternPtr = pattern)
lock (_createRegexSync)
{
_regex = OnigInterop.onigwrap_create(
patternPtr,
Encoding.Unicode.GetByteCount(patternPtr, pattern.Length),
ignoreCaseArg,
multilineArg);
fixed (char* patternPtr = pattern)
{
_regex = OnigInterop.onigwrap_create(
patternPtr,
Encoding.Unicode.GetByteCount(patternPtr, pattern.Length),
ignoreCaseArg,
multilineArg);
}
}

if (!Valid)
Expand Down

0 comments on commit bd074b7

Please sign in to comment.