Remove inefficiency in HttpStatus.series()
Prior to this commit, the Series value for an HttpStatus was always evaluated which resulted in an allocation of a Series array by invoking Series.values() which makes a defensive copy. This commit addresses this issue by hardcoding the corresponding Series within the HttpStatus constructor, thereby avoiding any unnecessary computations. In addition, a unit test has been added to verify that all HttpStatus enum constants have a properly configured Series. Closes gh-22366
This commit is contained in:
@@ -128,4 +128,12 @@ public class HttpStatusTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allStatusSeriesShouldMatchExpectations() {
|
||||
// a series of a status is manually set, make sure it is the correct one
|
||||
for (HttpStatus status : HttpStatus.values()) {
|
||||
HttpStatus.Series expectedSeries = HttpStatus.Series.valueOf(status.value());
|
||||
assertThat(expectedSeries).isEqualTo(status.series());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user