diff --git a/bin/generate_sequence.dart b/bin/generate_sequence.dart index c854715c..e03e6ca1 100644 --- a/bin/generate_sequence.dart +++ b/bin/generate_sequence.dart @@ -157,7 +157,7 @@ Future generateImplementation(int index) async { out.writeln('/// Converts this [Record] with $index positional values to ' 'a new type [R] using'); out.writeln('/// the provided [callback] with $index positional arguments.'); - out.writeln('@inlineVm @inlineJs'); + out.writeln('@inline'); out.writeln('R map(R Function(${valueTypes.join(', ')}) callback) => ' 'callback(${valueNames.join(', ')});'); out.writeln('}'); diff --git a/lib/src/core/context.dart b/lib/src/core/context.dart index 27e10f13..9344a627 100644 --- a/lib/src/core/context.dart +++ b/lib/src/core/context.dart @@ -18,15 +18,13 @@ class Context { final int position; /// Returns a result indicating a parse success. - @inlineVm - @inlineJs + @inline @useResult Success success(R result, [int? position]) => Success(buffer, position ?? this.position, result); /// Returns a result indicating a parse failure. - @inlineVm - @inlineJs + @inline @useResult Failure failure(String message, [int? position]) => Failure(buffer, position ?? this.position, message); diff --git a/lib/src/core/parser.dart b/lib/src/core/parser.dart index 77c7a463..ba0bdd72 100644 --- a/lib/src/core/parser.dart +++ b/lib/src/core/parser.dart @@ -135,8 +135,7 @@ abstract class Parser { /// makes it possible to wrap the parser without loosing type information. @internal @nonVirtual - @inlineVm - @inlineJs + @inline T captureResultGeneric(T Function(Parser self) callback) => callback(this); diff --git a/lib/src/core/result.dart b/lib/src/core/result.dart index 92a82815..3bcf9214 100644 --- a/lib/src/core/result.dart +++ b/lib/src/core/result.dart @@ -34,9 +34,11 @@ class Success extends Result { bool get isSuccess => true; @override + @inlineVm final R value; @override + @inlineVm String get message => throw UnsupportedError('Successful parse results do not have a message.'); @@ -53,9 +55,11 @@ class Failure extends Result { bool get isFailure => true; @override + @inlineVm Never get value => throw ParserException(this); @override + @inlineVm final String message; @override diff --git a/lib/src/parser/action/trimming.dart b/lib/src/parser/action/trimming.dart index d6611f8c..cc4900a2 100644 --- a/lib/src/parser/action/trimming.dart +++ b/lib/src/parser/action/trimming.dart @@ -55,8 +55,7 @@ class TrimmingParser extends DelegateParser return result < 0 ? -1 : _trim(right, buffer, result); } - @inlineVm - @inlineJs + @inline int _trim(Parser parser, String buffer, int position) { for (;;) { final result = parser.fastParseOn(buffer, position); diff --git a/lib/src/parser/character/predicates/lookup.dart b/lib/src/parser/character/predicates/lookup.dart index 852adae5..a4c06641 100644 --- a/lib/src/parser/character/predicates/lookup.dart +++ b/lib/src/parser/character/predicates/lookup.dart @@ -31,10 +31,8 @@ final class LookupCharPredicate extends CharacterPredicate { bool test(int charCode) => start <= charCode && charCode <= stop && _testBit(charCode - start); - @inlineJs - @inlineVm - @noBoundsChecksVm - @noBoundsChecksJs + @inline + @noBoundsChecks bool _testBit(int value) => (bits[value >> _shift] & _mask[value & _offset]) != 0; diff --git a/lib/src/parser/character/predicates/ranges.dart b/lib/src/parser/character/predicates/ranges.dart index 04e8516c..bfca0295 100644 --- a/lib/src/parser/character/predicates/ranges.dart +++ b/lib/src/parser/character/predicates/ranges.dart @@ -22,8 +22,7 @@ final class RangesCharPredicate extends CharacterPredicate { final Uint32List ranges; @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks bool test(int charCode) { var min = 0; var max = ranges.length - 2; diff --git a/lib/src/parser/combinator/generated/sequence_2.dart b/lib/src/parser/combinator/generated/sequence_2.dart index d559a597..cca87119 100644 --- a/lib/src/parser/combinator/generated/sequence_2.dart +++ b/lib/src/parser/combinator/generated/sequence_2.dart @@ -78,8 +78,7 @@ class SequenceParser2 extends Parser<(R1, R2)> extension RecordOfValuesExtension2 on (T1, T2) { /// Converts this [Record] with 2 positional values to a new type [R] using /// the provided [callback] with 2 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2) callback) => callback($1, $2); } diff --git a/lib/src/parser/combinator/generated/sequence_3.dart b/lib/src/parser/combinator/generated/sequence_3.dart index f6082268..c7284911 100644 --- a/lib/src/parser/combinator/generated/sequence_3.dart +++ b/lib/src/parser/combinator/generated/sequence_3.dart @@ -91,8 +91,7 @@ class SequenceParser3 extends Parser<(R1, R2, R3)> extension RecordOfValuesExtension3 on (T1, T2, T3) { /// Converts this [Record] with 3 positional values to a new type [R] using /// the provided [callback] with 3 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3) callback) => callback($1, $2, $3); } diff --git a/lib/src/parser/combinator/generated/sequence_4.dart b/lib/src/parser/combinator/generated/sequence_4.dart index 78be8f01..e6c34c70 100644 --- a/lib/src/parser/combinator/generated/sequence_4.dart +++ b/lib/src/parser/combinator/generated/sequence_4.dart @@ -99,8 +99,7 @@ class SequenceParser4 extends Parser<(R1, R2, R3, R4)> extension RecordOfValuesExtension4 on (T1, T2, T3, T4) { /// Converts this [Record] with 4 positional values to a new type [R] using /// the provided [callback] with 4 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3, T4) callback) => callback($1, $2, $3, $4); } diff --git a/lib/src/parser/combinator/generated/sequence_5.dart b/lib/src/parser/combinator/generated/sequence_5.dart index 2778c642..ff99ba26 100644 --- a/lib/src/parser/combinator/generated/sequence_5.dart +++ b/lib/src/parser/combinator/generated/sequence_5.dart @@ -118,8 +118,7 @@ class SequenceParser5 extends Parser<(R1, R2, R3, R4, R5)> extension RecordOfValuesExtension5 on (T1, T2, T3, T4, T5) { /// Converts this [Record] with 5 positional values to a new type [R] using /// the provided [callback] with 5 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3, T4, T5) callback) => callback($1, $2, $3, $4, $5); } diff --git a/lib/src/parser/combinator/generated/sequence_6.dart b/lib/src/parser/combinator/generated/sequence_6.dart index 11293187..15991752 100644 --- a/lib/src/parser/combinator/generated/sequence_6.dart +++ b/lib/src/parser/combinator/generated/sequence_6.dart @@ -135,8 +135,7 @@ extension RecordOfValuesExtension6 on ( ) { /// Converts this [Record] with 6 positional values to a new type [R] using /// the provided [callback] with 6 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3, T4, T5, T6) callback) => callback($1, $2, $3, $4, $5, $6); } diff --git a/lib/src/parser/combinator/generated/sequence_7.dart b/lib/src/parser/combinator/generated/sequence_7.dart index 4b2c3886..fee8b465 100644 --- a/lib/src/parser/combinator/generated/sequence_7.dart +++ b/lib/src/parser/combinator/generated/sequence_7.dart @@ -145,8 +145,7 @@ extension RecordOfValuesExtension7 on ( ) { /// Converts this [Record] with 7 positional values to a new type [R] using /// the provided [callback] with 7 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3, T4, T5, T6, T7) callback) => callback($1, $2, $3, $4, $5, $6, $7); } diff --git a/lib/src/parser/combinator/generated/sequence_8.dart b/lib/src/parser/combinator/generated/sequence_8.dart index 0da50f38..71f015a7 100644 --- a/lib/src/parser/combinator/generated/sequence_8.dart +++ b/lib/src/parser/combinator/generated/sequence_8.dart @@ -157,8 +157,7 @@ extension RecordOfValuesExtension8 on ( ) { /// Converts this [Record] with 8 positional values to a new type [R] using /// the provided [callback] with 8 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3, T4, T5, T6, T7, T8) callback) => callback($1, $2, $3, $4, $5, $6, $7, $8); } diff --git a/lib/src/parser/combinator/generated/sequence_9.dart b/lib/src/parser/combinator/generated/sequence_9.dart index 23b23978..f77c2b83 100644 --- a/lib/src/parser/combinator/generated/sequence_9.dart +++ b/lib/src/parser/combinator/generated/sequence_9.dart @@ -177,8 +177,7 @@ extension RecordOfValuesExtension9 on ( ) { /// Converts this [Record] with 9 positional values to a new type [R] using /// the provided [callback] with 9 positional arguments. - @inlineVm - @inlineJs + @inline R map(R Function(T1, T2, T3, T4, T5, T6, T7, T8, T9) callback) => callback($1, $2, $3, $4, $5, $6, $7, $8, $9); } diff --git a/lib/src/parser/predicate/single_character.dart b/lib/src/parser/predicate/single_character.dart index 42220c50..d42642bf 100644 --- a/lib/src/parser/predicate/single_character.dart +++ b/lib/src/parser/predicate/single_character.dart @@ -28,8 +28,7 @@ class SingleCharacterParser extends CharacterParser { : super.internal(); @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks Result parseOn(Context context) { final buffer = context.buffer; final position = context.position; @@ -40,8 +39,7 @@ class SingleCharacterParser extends CharacterParser { } @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks int fastParseOn(String buffer, int position) => position < buffer.length && predicate.test(buffer.codeUnitAt(position)) ? position + 1 @@ -60,8 +58,7 @@ class AnySingleCharacterParser extends SingleCharacterParser { super.internal(); @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks Result parseOn(Context context) { final buffer = context.buffer; final position = context.position; @@ -71,8 +68,7 @@ class AnySingleCharacterParser extends SingleCharacterParser { } @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks int fastParseOn(String buffer, int position) => position < buffer.length ? position + 1 : -1; } diff --git a/lib/src/parser/predicate/unicode_character.dart b/lib/src/parser/predicate/unicode_character.dart index e05adeab..55cf87c2 100644 --- a/lib/src/parser/predicate/unicode_character.dart +++ b/lib/src/parser/predicate/unicode_character.dart @@ -29,8 +29,7 @@ class UnicodeCharacterParser extends CharacterParser { : super.internal(); @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks Result parseOn(Context context) { final buffer = context.buffer; final position = context.position; @@ -53,8 +52,7 @@ class UnicodeCharacterParser extends CharacterParser { } @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks int fastParseOn(String buffer, int position) { if (position < buffer.length) { var codeUnit = buffer.codeUnitAt(position++); @@ -85,8 +83,7 @@ class AnyUnicodeCharacterParser extends UnicodeCharacterParser { super.internal(); @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks Result parseOn(Context context) { final buffer = context.buffer; final position = context.position; @@ -104,8 +101,7 @@ class AnyUnicodeCharacterParser extends UnicodeCharacterParser { } @override - @noBoundsChecksVm - @noBoundsChecksJs + @noBoundsChecks int fastParseOn(String buffer, int position) { if (position < buffer.length) { if (_isLeadSurrogate(buffer.codeUnitAt(position++)) && @@ -123,17 +119,14 @@ class AnyUnicodeCharacterParser extends UnicodeCharacterParser { // https://github.com/dart-lang/sdk/blob/1207250b0d5687f9016cf115068addf6593dba58/sdk/lib/core/string.dart#L932-L955 // Tests if the code is a UTF-16 lead surrogate. -@inlineVm -@inlineJs +@inline bool _isLeadSurrogate(int code) => (code & 0xFC00) == 0xD800; // Tests if the code is a UTF-16 trail surrogate. -@inlineVm -@inlineJs +@inline bool _isTrailSurrogate(int code) => (code & 0xFC00) == 0xDC00; // Combines a lead and a trail surrogate value into a single code point. -@inlineVm -@inlineJs +@inline int _combineSurrogatePair(int start, int end) => 0x10000 + ((start & 0x3FF) << 10) + (end & 0x3FF); diff --git a/lib/src/shared/annotations.dart b/lib/src/shared/annotations.dart index 9bcdfc2a..bd41a703 100644 --- a/lib/src/shared/annotations.dart +++ b/lib/src/shared/annotations.dart @@ -1,7 +1,12 @@ +/// Tests if the code is targeting JavaScript. +const isJavaScript = identical(1, 1.0); + // Request a function to be inlined. -const inlineVm = pragma('vm:prefer-inline'); +const inline = isJavaScript ? inlineJs : inlineVm; const inlineJs = pragma('dart2js:tryInline'); +const inlineVm = pragma('vm:prefer-inline'); // Removes all array bounds checks. -const noBoundsChecksVm = pragma('vm:unsafe:no-bounds-checks'); +const noBoundsChecks = isJavaScript ? noBoundsChecksJs : noBoundsChecksVm; const noBoundsChecksJs = pragma('dart2js:index-bounds:trust'); +const noBoundsChecksVm = pragma('vm:unsafe:no-bounds-checks');