Skip to content

Commit

Permalink
UseResult annotation to signal that a method should return a copy of …
Browse files Browse the repository at this point in the history
…the collection, instead of mutating it.
  • Loading branch information
marcglasberg committed Nov 10, 2023
1 parent 3832452 commit 69a115c
Show file tree
Hide file tree
Showing 39 changed files with 260 additions and 650 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [9.2.0] - 2023/11/10

* @useResult annotation to signal that a method should return a copy of the collection, instead of
mutating it.

## [9.1.6] - 2023/10/08

* Small docs improvement.
Expand Down
6 changes: 0 additions & 6 deletions example/benchmark/benchmark_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import "package:benchmark_app/screens/collection_choice_screen.dart";
import "package:benchmark_app/widgets/release_mode_warning.dart";
import "package:flutter/material.dart";



void main() => runApp(const BenchmarkApp());



class BenchmarkApp extends StatelessWidget {
const BenchmarkApp();

Expand All @@ -29,5 +25,3 @@ class BenchmarkApp extends StatelessWidget {
);
}
}


4 changes: 0 additions & 4 deletions example/benchmark/benchmark_app/lib/screens/code_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import "dart:io";
import "package:benchmark_app/widgets/collection_button.dart";
import "package:flutter/material.dart";



class CodeScreen extends StatelessWidget {
final String description;
final Map<String, String> code;
Expand Down Expand Up @@ -108,5 +106,3 @@ class _CodeBlock extends StatelessWidget {
);
}
}


20 changes: 4 additions & 16 deletions example/benchmark/benchmark_app/lib/screens/graph_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import "package:benchmark_app/widgets/bar_chart.dart";
import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart";
import "package:flutter/material.dart";



class GraphScreen extends StatefulWidget {
final String title;
final List<RecordsTable>? tables;
Expand All @@ -17,8 +15,6 @@ class GraphScreen extends StatefulWidget {
_GraphScreenState createState() => _GraphScreenState();
}



class _GraphScreenState extends State<GraphScreen> {
static final BoxDecoration bottomDecoration = BoxDecoration(
color: Colors.blue,
Expand Down Expand Up @@ -144,8 +140,6 @@ class _GraphScreenState extends State<GraphScreen> {
}
}



class _DropdownButton extends StatelessWidget {
//
final VoidCallback onTap;
Expand All @@ -159,13 +153,13 @@ class _DropdownButton extends StatelessWidget {
onTap: onTap,
child: Container(
margin: const EdgeInsets.only(top: 8, bottom: 16, left: 8, right: 8),
child: ColoredBox(
color: const Color(0x22000000),
child: const ColoredBox(
color: Color(0x22000000),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12.0),
padding: EdgeInsets.symmetric(vertical: 12.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
children: [
Text("Filters", style: TextStyle(fontSize: 20)),
Icon(Icons.arrow_drop_down),
],
Expand All @@ -178,8 +172,6 @@ class _DropdownButton extends StatelessWidget {
}
}



class _FilterDialog extends StatefulWidget {
//
final Map<String, bool> filters;
Expand All @@ -191,8 +183,6 @@ class _FilterDialog extends StatefulWidget {
_FilterDialogState createState() => _FilterDialogState();
}



class _FilterDialogState extends State<_FilterDialog> {
//
Map<String, bool> get filters => widget.filters;
Expand Down Expand Up @@ -252,5 +242,3 @@ class _FilterDialogState extends State<_FilterDialog> {
);
}
}


8 changes: 0 additions & 8 deletions example/benchmark/benchmark_app/lib/utils/benchmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import "package:flutter/material.dart";
/// Be careful with the parameters. If they are too big, you might encounter a difficult-to-debug
/// error, probably due to insufficient memory.


final List<Widget> listBenchmarks = [
BenchWidget(
title: "List.add",
Expand Down Expand Up @@ -113,8 +111,6 @@ final List<Widget> listBenchmarks = [
),
];



final List<Widget> setBenchmarks = [
BenchWidget(
title: "Set.add",
Expand Down Expand Up @@ -220,8 +216,6 @@ final List<Widget> setBenchmarks = [
),
];



final List<Widget> mapBenchmarks = [
BenchWidget(
title: "Map.add",
Expand Down Expand Up @@ -308,5 +302,3 @@ final List<Widget> mapBenchmarks = [
],
),
];


Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


abstract class ListCode {
static const Map<String, String> add = {
"List (Mutable)": "for (int i = 0; i < innerRuns; i++)\n" " _list.add(i);",
Expand Down Expand Up @@ -67,8 +65,6 @@ abstract class ListCode {
};
}



abstract class SetCode {
static const Map<String, String> add = {
"Set (Mutable)": "_set = Set<int>.of(_fixedSet);\n"
Expand Down Expand Up @@ -121,8 +117,6 @@ abstract class SetCode {
};
}



abstract class MapCode {
static const Map<String, String> add = {
"Map (Mutable)": "for (int i = 0; i < initialLength + innerRuns(); i++)\n"
Expand Down Expand Up @@ -178,5 +172,3 @@ abstract class MapCode {
" => mapBuilder.remove((config.size ~/ 2).toString()));",
};
}


4 changes: 0 additions & 4 deletions example/benchmark/benchmark_app/lib/widgets/bar_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import "package:charts_flutter/flutter.dart" as charts;
import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart";
import "package:flutter/material.dart";



class BarChart extends StatelessWidget {
final RecordsTable recordsTable;

Expand Down Expand Up @@ -56,5 +54,3 @@ class BarChart extends StatelessWidget {
);
}
}


10 changes: 1 addition & 9 deletions example/benchmark/benchmark_app/lib/widgets/bench_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import "package:benchmark_app/widgets/collection_button.dart";
import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart";
import "package:flutter/material.dart";



class BenchWidget extends StatefulWidget {
final String title;
final Map<String, String> code;
Expand All @@ -24,8 +22,6 @@ class BenchWidget extends StatefulWidget {
_BenchWidgetState createState() => _BenchWidgetState();
}



class _BenchWidgetState extends State<BenchWidget> {
bool _isRunning = false;
List<RecordsTable>? _results;
Expand Down Expand Up @@ -126,10 +122,8 @@ class _BenchWidgetState extends State<BenchWidget> {
}
}



class _PleaseWait extends StatelessWidget {
const _PleaseWait({Key? key}) : super(key: key);
const _PleaseWait({super.key});

@override
Widget build(_) {
Expand All @@ -156,5 +150,3 @@ class _PleaseWait extends StatelessWidget {
);
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import "package:flutter/material.dart";



class CollectionButton extends StatelessWidget {
final String label;
final VoidCallback? onPressed;
Expand All @@ -22,5 +20,3 @@ class CollectionButton extends StatelessWidget {
);
}
}


Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import "package:flutter/foundation.dart";
import "package:flutter/material.dart";



class ReleaseModeWarning extends StatelessWidget {
const ReleaseModeWarning();

Expand All @@ -28,5 +26,3 @@ class ReleaseModeWarning extends StatelessWidget {
);
}
}


34 changes: 8 additions & 26 deletions example/benchmark/lib/src/cases/list/add.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,22 @@ import "package:fast_immutable_collections/fast_immutable_collections.dart";
import "package:fast_immutable_collections_benchmarks/fast_immutable_collections_benchmarks.dart";
import "package:kt_dart/kt.dart";



class ListAddBenchmark extends MultiBenchmarkReporter<ListBenchmarkBase> {
@override
final List<ListBenchmarkBase> benchmarks;

ListAddBenchmark({required TableScoreEmitter emitter})
ListAddBenchmark({required super.emitter})
: benchmarks = <ListBenchmarkBase>[
MutableListAddBenchmark(emitter: emitter),
IListAddBenchmark(emitter: emitter),
KtListAddBenchmark(emitter: emitter),
BuiltListAddWithRebuildBenchmark(emitter: emitter),
BuiltListAddWithListBuilderBenchmark(emitter: emitter),
],
super(emitter: emitter);
];
}



class MutableListAddBenchmark extends ListBenchmarkBase {
MutableListAddBenchmark({required TableScoreEmitter emitter})
: super(name: "List (Mutable)", emitter: emitter);
MutableListAddBenchmark({required super.emitter}) : super(name: "List (Mutable)");

late List<int> list;

Expand Down Expand Up @@ -65,10 +59,8 @@ class MutableListAddBenchmark extends ListBenchmarkBase {
}
}



class IListAddBenchmark extends ListBenchmarkBase {
IListAddBenchmark({required TableScoreEmitter emitter}) : super(name: "IList", emitter: emitter);
IListAddBenchmark({required super.emitter}) : super(name: "IList");

late IList<int> iList;
late IList<int> result;
Expand All @@ -90,11 +82,8 @@ class IListAddBenchmark extends ListBenchmarkBase {
}
}



class KtListAddBenchmark extends ListBenchmarkBase {
KtListAddBenchmark({required TableScoreEmitter emitter})
: super(name: "KtList", emitter: emitter);
KtListAddBenchmark({required super.emitter}) : super(name: "KtList");

late KtList<int> ktList;
late KtList<int> result;
Expand All @@ -114,11 +103,8 @@ class KtListAddBenchmark extends ListBenchmarkBase {
}
}



class BuiltListAddWithRebuildBenchmark extends ListBenchmarkBase {
BuiltListAddWithRebuildBenchmark({required TableScoreEmitter emitter})
: super(name: "BuiltList (Rebuild)", emitter: emitter);
BuiltListAddWithRebuildBenchmark({required super.emitter}) : super(name: "BuiltList (Rebuild)");

late BuiltList<int> builtList;
late BuiltList<int> result;
Expand All @@ -139,11 +125,9 @@ class BuiltListAddWithRebuildBenchmark extends ListBenchmarkBase {
}
}



class BuiltListAddWithListBuilderBenchmark extends ListBenchmarkBase {
BuiltListAddWithListBuilderBenchmark({required TableScoreEmitter emitter})
: super(name: "BuiltList (ListBuilder)", emitter: emitter);
BuiltListAddWithListBuilderBenchmark({required super.emitter})
: super(name: "BuiltList (ListBuilder)");

late BuiltList<int> builtList;
late BuiltList<int> result;
Expand All @@ -163,5 +147,3 @@ class BuiltListAddWithListBuilderBenchmark extends ListBenchmarkBase {
result = listBuilder.build();
}
}


Loading

0 comments on commit 69a115c

Please sign in to comment.