/** Compacts a set of message parts. */ private ImmutableList<SoyMsgPart> compactParts(ImmutableList<SoyMsgPart> parts) { ImmutableList.Builder<SoyMsgPart> builder = ImmutableList.builder(); for (SoyMsgPart part : parts) { builder.add(compactPart(part)); } return builder.build(); }
/** * Compacts a single message part. * * <p>If the part is a plural/select part, it might be expanded into multiple parts. */ private SoyMsgPart compactPart(SoyMsgPart part) { if (part instanceof SoyMsgPluralPart) { part = compactPlural((SoyMsgPluralPart) part); } else if (part instanceof SoyMsgSelectPart) { part = compactSelect((SoyMsgSelectPart) part); } else if (part instanceof SoyMsgPlaceholderPart) { part = compactPlaceholder((SoyMsgPlaceholderPart) part); } // Now intern the message part. return intern(part); }
private SoyMsgPart compactSelect(SoyMsgSelectPart select) { // TODO: Turn into a non-select message if there's only one unique case. // Select variable names tend to be repeated across many templates, like "gender". return new SoyMsgSelectPart( intern(select.getSelectVarName()), compactCases(select.getCases(), DEFAULT_SELECT_CASE_SPEC)); }
caseAndValue.spec() != null ? intern(caseAndValue.spec()) : null, compactParts(caseAndValue.parts())));
private SoyMsgPart compactPlaceholder(SoyMsgPlaceholderPart part) { return new SoyMsgPlaceholderPart( intern(part.getPlaceholderName()), /* placeholderExample=*/ null); }
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
private SoyMsgPart compactSelect(SoyMsgSelectPart select) { // TODO: Turn into a non-select message if there's only one unique case. // Select variable names tend to be repeated across many templates, like "gender". return new SoyMsgSelectPart( intern(select.getSelectVarName()), compactCases(select.getCases(), DEFAULT_SELECT_CASE_SPEC)); }
caseAndValue.spec() != null ? intern(caseAndValue.spec()) : null, compactParts(caseAndValue.parts())));
private SoyMsgPart compactPlaceholder(SoyMsgPlaceholderPart part) { return new SoyMsgPlaceholderPart( intern(part.getPlaceholderName()), /* placeholderExample=*/ null); }
/** * Returns a more memory-efficient version of the internal message bundle. * * <p>Only enough information is retained for rendering; not enough for message extraction. As a * side effect, this SoyMsgBundleCompactor instance will also retain references to parts of the * messages in order to reuse identical objects. */ public SoyMsgBundle compact(SoyMsgBundle input) { ImmutableList.Builder<SoyMsg> builder = ImmutableList.builder(); for (SoyMsg msg : input) { ImmutableList<SoyMsgPart> parts = compactParts(msg.getParts()); builder.add( SoyMsg.builder() .setId(msg.getId()) .setLocaleString(msg.getLocaleString()) .setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts)) .setParts(parts) .build()); } return new RenderOnlySoyMsgBundleImpl(input.getLocaleString(), builder.build()); }
/** * Compacts a single message part. * * <p>If the part is a plural/select part, it might be expanded into multiple parts. */ private SoyMsgPart compactPart(SoyMsgPart part) { if (part instanceof SoyMsgPluralPart) { part = compactPlural((SoyMsgPluralPart) part); } else if (part instanceof SoyMsgSelectPart) { part = compactSelect((SoyMsgSelectPart) part); } else if (part instanceof SoyMsgPlaceholderPart) { part = compactPlaceholder((SoyMsgPlaceholderPart) part); } // Now intern the message part. return intern(part); }
private SoyMsgPart compactPlural(SoyMsgPluralPart plural) { // Plural variable names tend to be repeated across templates, such as "count". return new SoyMsgPluralPart( intern(plural.getPluralVarName()), plural.getOffset(), compactCases(plural.getCases(), DEFAULT_PLURAL_CASE_SPEC)); }
/** Compacts a set of message parts. */ private ImmutableList<SoyMsgPart> compactParts(ImmutableList<SoyMsgPart> parts) { ImmutableList.Builder<SoyMsgPart> builder = ImmutableList.builder(); for (SoyMsgPart part : parts) { builder.add(compactPart(part)); } return builder.build(); }
private SoyMsgPart compactPlural(SoyMsgPluralPart plural) { // Plural variable names tend to be repeated across templates, such as "count". return new SoyMsgPluralPart( intern(plural.getPluralVarName()), plural.getOffset(), compactCases(plural.getCases(), DEFAULT_PLURAL_CASE_SPEC)); }