use_string_buffers
Use string buffers to compose strings.
This rule is available as of Dart 2.0.
Details
#DO use string buffers to compose strings.
In most cases, using a string buffer is preferred for composing strings due to its improved performance.
BAD:
dart
String foo() {
final buffer = '';
for (int i = 0; i < 10; i++) {
buffer += 'a'; // LINT
}
return buffer;
}
GOOD:
dart
String foo() {
final buffer = StringBuffer();
for (int i = 0; i < 10; i++) {
buffer.write('a');
}
return buffer.toString();
}
Usage
#To enable the use_string_buffers
rule,
add use_string_buffers
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- use_string_buffers
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。