Skip to content

Commit

Permalink
[playframework#497] Reduced memory usage when rendering GroovyTemplat…
Browse files Browse the repository at this point in the history
…es using #{extends}

This is not a 'magic bullet' but it does use half the memory as the previous replace-strategy
  • Loading branch information
mbknor committed May 20, 2011
1 parent afb2d71 commit 08e604c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion framework/src/play/templates/GroovyTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,19 @@ protected String internalRender(Map<String, Object> args) {
layoutArgs.remove("out");
layoutArgs.put("_isLayout", true);
String layoutR = layout.get().internalRender(layoutArgs);
return layoutR.replace("____%LAYOUT%____", writer.toString().trim());

// Must replace '____%LAYOUT%____' inside the string layoutR with the content from writer..
final String whatToFind = "____%LAYOUT%____";
final int pos = layoutR.indexOf(whatToFind);
if (pos >=0) {
// prepending and appending directly to writer/buffer to prevent us
// from having to duplicate the string.
// this makes us use half of the memory!
writer.getBuffer().insert(0,layoutR.substring(0,pos));
writer.append(layoutR.substring(pos+whatToFind.length()));
return writer.toString().trim();
}
return layoutR;
}
if (writer != null) {
return writer.toString();
Expand Down

0 comments on commit 08e604c

Please sign in to comment.