Skip to content

use_string_buffers reports, although intermediate strings are used #57777

Closed
@Hixie

Description

@Hixie

The first block in the following pattern triggers use_string_buffers but the second block (which uses StringBuffer) is ~7% slower:

const int count = 100000;

void test(String s) { }

void main() {
  Stopwatch t = new Stopwatch();

  // USING STRING
  t.start();
  String s = '';
  for (int i = 0; i < count; i += 1) {
    s = s + '-$i';
    test(s);
  }
  print(t.elapsedMicroseconds);

  // USING STRINGBUFFER
  t.reset();
  StringBuffer b = new StringBuffer();
  for (int i = 0; i < count; i += 1) {
    b.write('-$i');
    test(b.toString());
  }
  print(t.elapsedMicroseconds);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work ondevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions