Author: ericwa
Date: Thu Mar 20 02:43:29 2014
New Revision: 10591

URL: http://svn.gna.org/viewcvs/etoile?rev=10591&view=rev
Log:
Typewriter: cache the committed state of a note in an ivar, used for computing 
the attributed string diff for the commit description, so we can avoid calling 
-objectGraphContextForPreviewingRevision: which is slow.

Modified:
    
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
    
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m

Modified: 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h?rev=10591&r1=10590&r2=10591&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
        (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
        Thu Mar 20 02:43:29 2014
@@ -44,6 +44,7 @@
        BOOL changedByUser;
        NSTimer *coalescingTimer;
        BOOL isDeleting;
+       COObjectGraphContext *selectedNoteCommittedState;
 }
 
 @property (nonatomic, readonly) NSTableView *notesTable;

Modified: 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m?rev=10591&r1=10590&r2=10591&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m
        (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m
        Thu Mar 20 02:43:29 2014
@@ -576,8 +576,9 @@
        TypewriterDocument *doc = [selectedNote rootObject];
        COAttributedString *as = doc.attrString;
        
-       COObjectGraphContext *oldDocCtx = [selectedNote 
objectGraphContextForPreviewingRevision: [selectedNote currentRevision]];
-       TypewriterDocument *oldDoc = [oldDocCtx rootObject];
+       // NOTE: selectedNoteCommittedState is equal to [selectedNote 
objectGraphContextForPreviewingRevision: [selectedNote currentRevision]];
+       // we could use that instead but it's too expensive to call 
-objectGraphContextForPreviewingRevision:.
+       TypewriterDocument *oldDoc = [selectedNoteCommittedState rootObject];
        COAttributedString *oldAs = oldDoc.attrString;
        
        // HACK: -[COAttributedStringDiff 
initWithFirstAttributedString:secondAttributedString:source:] will throw an 
exception
@@ -651,6 +652,10 @@
                NSLog(@"Can't write description for diff: %@", diff);
        }
 
+       // Update selectedNoteCommittedState to reflect the commit
+       NSArray *objectsToUpdateInSnapshot = (NSArray 
*)[[[selectedNote.objectGraphContext changedObjects] mappedCollection] 
storeItem];
+       [selectedNoteCommittedState insertOrUpdateItems: 
objectsToUpdateInSnapshot];
+       
        [self commitWithIdentifier: identifier descriptionArguments: descArgs];
 }
 
@@ -723,6 +728,10 @@
 {
        selectedNote = aNote;
        
+       // Make a temporary copy of the note's current state. We use this to 
generate the diff for the commit metadata.
+       selectedNoteCommittedState = [COObjectGraphContext new];
+       [selectedNoteCommittedState setItemGraph: 
selectedNote.objectGraphContext];
+       
        if (selectedNote == nil)
        {
                // Nothing selected


_______________________________________________
Etoile-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-cvs

Reply via email to