Skip to content

Commit

Permalink
Return static DefaultApplicationStartup step
Browse files Browse the repository at this point in the history
This commit ensures that `DefaultApplicationStartup` returns a static
step for each call to avoid allocations.

Closes spring-projectsgh-26939
  • Loading branch information
bclozel authored and lxbzmy committed Mar 26, 2022
1 parent 8d96dc1 commit 21132ba
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,16 +29,16 @@
*/
class DefaultApplicationStartup implements ApplicationStartup {

private static final DefaultStartupStep DEFAULT_STARTUP_STEP = new DefaultStartupStep();

@Override
public DefaultStartupStep start(String name) {
return new DefaultStartupStep();
return DEFAULT_STARTUP_STEP;
}


static class DefaultStartupStep implements StartupStep {

boolean recorded = false;

private final DefaultTags TAGS = new DefaultTags();

@Override
Expand All @@ -63,23 +63,17 @@ public Tags getTags() {

@Override
public StartupStep tag(String key, String value) {
if (this.recorded) {
throw new IllegalArgumentException();
}
return this;
}

@Override
public StartupStep tag(String key, Supplier<String> value) {
if (this.recorded) {
throw new IllegalArgumentException();
}
return this;
}

@Override
public void end() {
this.recorded = true;

}


Expand Down

0 comments on commit 21132ba

Please sign in to comment.