@@ -152,12 +152,6 @@ public Enumeration<URL> getResources(String nm) throws IOException {
152152 //for single resources we still respect this
153153 boolean banned = state .bannedResources .contains (name );
154154 Set <URL > resources = new LinkedHashSet <>();
155- //ClassPathElement[] providers = loadableResources.get(name);
156- //if (providers != null) {
157- // for (ClassPathElement element : providers) {
158- // resources.add(element.getResource(nm).getUrl());
159- // }
160- //}
161155
162156 //this is a big of a hack, but is necessary to prevent service leakage
163157 //in some situations (looking at you gradle) the parent can contain the same
@@ -179,10 +173,12 @@ public Enumeration<URL> getResources(String nm) throws IOException {
179173 //ignore
180174 }
181175 }
182- for (ClassPathElement i : elements ) {
183- ClassPathResource res = i .getResource (nm );
184- if (res != null ) {
185- resources .add (res .getUrl ());
176+ //TODO: in theory resources could have been added in dev mode
177+ //but I don't thing this really matters for this code path
178+ ClassPathElement [] providers = state .loadableResources .get (name );
179+ if (providers != null ) {
180+ for (ClassPathElement element : providers ) {
181+ resources .add (element .getResource (nm ).getUrl ());
186182 }
187183 }
188184 if (!banned ) {
@@ -259,15 +255,20 @@ public URL getResource(String nm) {
259255 if (state .bannedResources .contains (name )) {
260256 return null ;
261257 }
262- // ClassPathElement[] providers = loadableResources.get(name);
263- // if (providers != null) {
264- // return providers[0].getResource(nm).getUrl();
265- // }
266- //TODO: because of dev mode we can't use the fast path her, we need to iterate
267- for (ClassPathElement i : elements ) {
268- ClassPathResource res = i .getResource (name );
269- if (res != null ) {
270- return res .getUrl ();
258+ //TODO: because of dev mode we iterate, to see if any resources were added
259+ //not for .class files though, adding them causes a restart
260+ //this is very important for bytebuddy performance
261+ if (nm .endsWith (".class" )) {
262+ ClassPathElement [] providers = state .loadableResources .get (name );
263+ if (providers != null ) {
264+ return providers [0 ].getResource (nm ).getUrl ();
265+ }
266+ } else {
267+ for (ClassPathElement i : elements ) {
268+ ClassPathResource res = i .getResource (name );
269+ if (res != null ) {
270+ return res .getUrl ();
271+ }
271272 }
272273 }
273274 return parent .getResource (nm );
@@ -280,15 +281,18 @@ public InputStream getResourceAsStream(String nm) {
280281 if (state .bannedResources .contains (name )) {
281282 return null ;
282283 }
283- // ClassPathElement[] providers = loadableResources.get(name);
284- // if (providers != null) {
285- // return new ByteArrayInputStream(providers[0].getResource(nm).getData());
286- // }
287- //TODO: because of dev mode we can't use the fast path her, we need to iterate
288- for (ClassPathElement i : elements ) {
289- ClassPathResource res = i .getResource (name );
290- if (res != null ) {
291- return new ByteArrayInputStream (res .getData ());
284+ //dev mode may have added some files, so we iterate to check, but not for classes
285+ if (nm .endsWith (".class" )) {
286+ ClassPathElement [] providers = state .loadableResources .get (name );
287+ if (providers != null ) {
288+ return new ByteArrayInputStream (providers [0 ].getResource (nm ).getData ());
289+ }
290+ } else {
291+ for (ClassPathElement i : elements ) {
292+ ClassPathResource res = i .getResource (name );
293+ if (res != null ) {
294+ return new ByteArrayInputStream (res .getData ());
295+ }
292296 }
293297 }
294298 return parent .getResourceAsStream (nm );
0 commit comments