Integrated: 8274261: Use enhanced-for instead of plain 'for' in jdk.jcmd
Andrey Turbanov
duke at openjdk.java.net
Tue Nov 16 11:16:41 UTC 2021
On Fri, 24 Sep 2021 07:30:02 GMT, Andrey Turbanov <duke at openjdk.java.net> wrote:
> There are few places in code where manual `for` loop is used with Iterator to iterate over Collection or Array.
> Instead of manual `for` cycles it's preferred to use enhanced-for cycle instead: it's less verbose, makes code easier to read and it's less error-prone.
> It doesn't have any performance impact: javac compiler generates similar code when compiling enhanced-for cycle.
>
> One strange thing I also noticed is static field `sun.tools.jstat.Parser#reservedWords`, which filled in `Parser` constructor. Reworked to initialize it once.
This pull request has now been integrated.
Changeset: 20f3872d
Author: Andrey Turbanov <turbanoff at gmail.com>
Committer: Serguei Spitsyn <sspitsyn at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/20f3872d1cd6257ab9c76bb998f8dc2d07bc1724
Stats: 44 lines in 6 files changed: 0 ins; 14 del; 30 mod
8274261: Use enhanced-for instead of plain 'for' in jdk.jcmd
Reviewed-by: sspitsyn, cjplummer
-------------
PR: https://git.openjdk.java.net/jdk/pull/5673
More information about the serviceability-dev
mailing list