Ticket #2443: text_performance_r1.patch

File text_performance_r1.patch, 9.2 KB (added by boyanl, 15 years ago)
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/TextFuncModule.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
    100100                ResourceR4.registerAsExtension(res, HotTextResourceR4.class); 
    101101                 
    102102                // Logics 
    103                 SimpleOperation.fillExtensions(res, TextModelLogic.class); 
    104103                SimpleOperation.fillExtensions(res, HotTextLogic.class); 
    105104                SimpleOperation.fillExtensions(res, TextFrameLogic.class); 
    106105                SimpleOperation.fillExtensions(res, TextChainingLogic.class); 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/TextModelLogic.java

     
    9696                        HotLayoutPoint layoutPoint = new HotLayoutPoint(point, source.getIndex()); 
    9797                        int pos = textLayout.getHitIndex(layoutPoint); 
    9898 
    99                         if (eventID == InputEventR3.MOUSE_PRESSED ||  
    100                                         (eventID == InputEventR3.MOUSE_CLICKED && clickCount % 3 == 1)) { 
     99                        if ( eventID == InputEventR3.MOUSE_PRESSED /*||  
     100                                        (eventID == InputEventR3.MOUSE_CLICKED && clickCount % 3 == 1)*/) { 
    101101                                setSelection(source, pos, pos, true, source.getIndex()); 
    102102                                return false; 
    103103                        }  
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/links/TextLinkProcessor.java

     
    66import org.sophie2.base.commons.util.ImmColor; 
    77import org.sophie2.base.commons.util.ImmMap; 
    88import org.sophie2.base.model.text.HotAttr; 
     9import org.sophie2.base.model.text.TextChange; 
    910import org.sophie2.base.model.text.TextReplaceChange; 
    1011import org.sophie2.base.model.text.elements.CommonAttr; 
    1112import org.sophie2.base.model.text.model.ImmTextInterval; 
     
    130131 
    131132        public DefaultTextEffect applyChange(TextProcessorEffect prevEffect, ImmText oldSource, 
    132133                        ImmText oldResult, TextLinkOptions procOptions) { 
    133 //              TextChange change = prevEffect.getChange(); 
    134 //              ImmText sourceText = prevEffect.getText(); 
    135 //              ImmText toProcess = sourceText.subText(change.getTargetDamage(sourceText)); 
    136 // 
    137 //              TextReplaceChange effect = new TextReplaceChange( 
    138 //                              change.getSourceDamage(oldSource), process(toProcess, procOptions)); 
    139 // 
    140 //              ImmText result = effect.applyTo(oldResult); 
    141 //              assert result.getEnd() == sourceText.getEnd() : result.getEnd() + " : " + sourceText.getEnd(); 
    142 // 
    143 //              return new DefaultTextEffect(effect, result); 
     134                TextChange change = prevEffect.getChange(); 
     135                ImmText sourceText = prevEffect.getText(); 
    144136                 
    145                 ImmText res = process(prevEffect.getText(), procOptions); 
    146                 return new DefaultTextEffect(ImmTextUtils.getChange(oldResult, res), res); 
     137                ImmTextInterval targetDamage = change.getTargetDamage (sourceText); 
     138                ImmTextInterval sourceDamage = change.getSourceDamage(oldSource); 
     139                 
     140                //check if the change is within the text, and if there is anything to process 
     141                if (targetDamage.getBegin() >= sourceText.getBegin() &&  
     142                                targetDamage.getEnd() <= sourceText.getEnd() && 
     143                                ((sourceDamage.getBegin() < sourceDamage.getEnd ()) || 
     144                                                targetDamage.getBegin() < targetDamage.getEnd() ) 
     145                                                ) { 
     146                        ImmText toProcess = sourceText.subText(change.getTargetDamage(sourceText)); 
     147         
     148                        TextReplaceChange effect = new TextReplaceChange( 
     149                                        sourceDamage, process(toProcess, procOptions)); 
     150         
     151                        ImmText result = effect.applyTo(oldResult); 
     152                //      assert result.getEnd() == sourceText.getEnd() : result.getEnd() + " : " + sourceText.getEnd(); 
     153         
     154                        return new DefaultTextEffect(effect, result); 
     155                        } 
     156                //else { 
     157                int textBegin = sourceText.getBegin(); 
     158                TextReplaceChange effect = new TextReplaceChange(new ImmTextInterval(textBegin, textBegin), 
     159                                                                                                                 ImmTextUtils.createEmptyText()); 
     160                return new DefaultTextEffect(effect, sourceText); 
     161                // } 
    147162        } 
    148163 
    149164        public ImmText process(ImmText sourceText, TextLinkOptions procOptions) { 
     
    163178                                if (fgColor != null) { 
    164179 
    165180                                        values.put(CommonAttr.FOREGROUND_COLOR, fgColor); 
    166                                         unitStyle = unitStyle.derive(values); 
    167  
    168                                         // TODO performance could be better if the style is applied for a whole interval. 
    169                                         result = result.applyStyle(unitStyle, new ImmTextInterval(i, i+1)); 
     181                                        HotStyleDef style = HotStyleDef.getEmpty().derive (values); 
     182                                         
     183                                        /* 
     184                                         * Navigate until the end of the link in the text, then set the style for the whole interval 
     185                                         */ 
     186                                        int end = i+1; 
     187                                        while (end < sourceTextEnd) { 
     188                                                HotStyleDef nextStyle = sourceText.unitAt(end).getStyle(); 
     189                                                String nextLinkId = nextStyle.getValue (CommonAttr.LINK_ATTRIBUTE); 
     190                                                 
     191                                                if (!nextLinkId.equals(linkId)) 
     192                                                        break; 
     193                                                ++end; 
     194                                        } 
     195                                         
     196                                        result = result.applyStyle(style, new ImmTextInterval(i, end)); 
     197                                        i = end - 1; 
    170198                                } 
    171199                        } 
    172200                } 
     
    193221        } 
    194222 
    195223} 
     224 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/BaseTextModel.java

     
    296296         *                              The list of changes to be applied.    
    297297         */  
    298298        protected void update(List<TextChange> changes) { 
     299                ImmText processed = null; 
    299300                for (TextChange change : changes) { 
    300301 
    301302                        SelectionInfo info = caretInfo().get(); 
     
    310311                        } 
    311312 
    312313                        lastChange().set(change); 
     314                        processed = getProcessed (); 
    313315                } 
    314                 processedText().set(getProcessed()); 
     316                 
     317                if (processed != null) { 
     318                        processedText().set(getProcessed()); 
     319                } 
    315320        } 
    316321 
    317322        public void setSelectionInfo(int caretIndex, int markIndex) { 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/model/ImmHotText.java

     
    114114                        newTextUnits = newTextUnits.remove(index); 
    115115                } 
    116116 
    117                 int endRunIndex = getRunEnd(0); 
    118117                HotStyleDef newStyle  = newStyles; 
    119                 if (newText.getEnd() >= 1) { 
    120                         TextUnit unit = newText.unitAt(0); 
    121                         HotStyleDef style = unit.getStyle(); 
    122                                 newStyle = newStyle.derive(style); 
    123                 } 
    124  
     118                 
    125119                for (int i = 0; i < newText.getEnd(); ++i, ++index) { 
    126120                        TextUnit unit = newText.unitAt(i); 
    127                         if (i >= endRunIndex) { 
    128                                 HotStyleDef style = unit.getStyle(); 
    129                                 newStyle = newStyle.replaceDerive(style); 
    130                                 endRunIndex = getRunEnd(endRunIndex + 1); 
    131                         } 
    132  
     121                        newStyle = unit.getStyle(); 
     122                         
    133123                        newTextUnits =  
    134124                                newTextUnits.add(index, new TextUnit(unit.getChar(), newStyle)); 
    135125                } 
     
    242232                return new ImmHotText(this.textUnits.concat(otherHotText.textUnits)); 
    243233        } 
    244234 
     235        @SuppressWarnings("unused") 
    245236        private int getRunEnd(int i) { 
    246237                if (this.getEnd() <= i) { 
    247238                        return i; 
  • modules/org.sophie2.base.scene/src/main/java/org/sophie2/base/scene/events/SceneInteractionLogic.java

     
    145145                                boolean handled = false; 
    146146                                iterator = elementPath.listIterator(elementPath.size()); 
    147147                                while (iterator.hasPrevious() && !handled) { 
     148                                        element = iterator.previous(); 
    148149                                        if (SceneHelper.getElementPath(scene, element).isEmpty()) { 
    149150                                                // the scene has been changed and the element is no longer there 
    150151                                                break; 
     
    163164 
    164165                                                handled = LogicR3.fire(new EventR3(fields)); 
    165166                                        } 
    166  
    167                                         element = iterator.previous(); 
    168167                                } 
    169168 
    170169                                // fire for top controller 
     
    260259                        fields.set(EventR3.ID_INDEX, eventId); 
    261260                        boolean handled = false; 
    262261                        while (iterator.hasPrevious() && !handled) {                             
     262                                element = iterator.previous(); 
    263263                                if (SceneHelper.getElementPath(scene, element).isEmpty()) { 
    264264                                        // the scene has been changed and the element is no longer there 
    265265                                        break; 
     
    282282                                         
    283283                                        handled = LogicR3.fire(eventR3); 
    284284                                } 
    285  
    286                                 element = iterator.previous(); 
    287285                        } 
    288286 
    289287                        // fire for top controller