- for( int i=0; i<2; ++i ) {
- UndoStackItem *second = first->next;
- char *temp_data = 0;
-
-
- if( !second->is_key() ) {
- temp_data = second->get_data();
- }
- remove(first);
-
-// Convert new first to key buffer.
- if( !second->is_key() ) {
- second->set_data(temp_data);
- }
- delete [] temp_data;
+ UndoStackItem *item = first, *key = item;
+#ifdef UNDO_INCREMENTAL
+ for( int i=2; --i>=0; item=item->next );
+#else
+ for( int i=2; --i>=0; item=item->next )
+ if( item->is_key() ) key = item;
+#endif
+ char *data = !item->is_key() ? key->get_data() : 0;
+ while( first != item ) {
+ if( current == first ) current = first->next;
+ delete first;
+ }
+ if( data ) {
+ item->set_data(data);
+ delete [] data;