Sublime Forum

Replacing all \n causes apparent infinite loop

#1

I’m sure there’s a good reason why this is a bad idea but I was trying to strip out all newlines from a ~40,000 line file. I was in regex mode at first and replaced \n with a null string. single replace worked fine Replace all gave me a spinning beachball of death. I tried coping the newline instead of using regex mode, I tried turning of the loop back to the beginning option, I tried reversing the direction so it just has about 20 replaces to do. Still hung. It also seems to start eating memory after that.

I have a 2011 iMac with Mountain Lion.

Here’s the crash log from when I -9’d it:

Date/Time:       2013-02-20 11:26:10 -0700
OS Version:      10.8.2 (Build 12C60)
Architecture:    x86_64
Report Version:  11

Command:         Sublime Text 2
Path:            /Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2
Version:         Version 2.0.1, Build 2217 (2217)
Parent:          launchd [303]

PID:             50427
Event:           hang
Duration:        1.56s
Steps:           5 (100ms sampling interval)

Hardware model:  iMac12,1
Active cpus:     4
Free pages:      4695 pages (+4170)
Pageins:         41 pages
Pageouts:        706 pages


Process:         Sublime Text 2 [50427] (zombie)
Path:            /Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2
Architecture:    x86_64
Parent:          launchd [303]
UID:             502
Task size:       957265 pages (-3947)
CPU Time:        0.187s
Note:            Suspended for 2 samples
Note:            Terminated (zombie) for 2 samples

  Thread 0xa7eeed   DispatchQueue 1          priority <multiple> cpu time   0.187s
  3 start + 52 (Sublime Text 2) [0x104a11064]
    3 main + 2251 (Sublime Text 2) [0x104b023cb]
      3 -[NSApplication run] + 636 (AppKit) [0x7fff987b02fa]
        3 -[NSApplication sendEvent:] + 5761 (AppKit) [0x7fff9889a744]
          3 ??? (Sublime Text 2 + 2480409) [0x104c6c919]
            3 window_impl::handle_event(px_event_t*) + 227 (Sublime Text 2) [0x104a837e7]
              3 button_drag_handler::handle_event(px_event_t const*) + 411 (Sublime Text 2) [0x104a29997]
                3 find_panel::do_replace_all() + 24 (Sublime Text 2) [0x104acfa82]
                  3 find_state::replace_all() + 254 (Sublime Text 2) [0x104ad5624]
                    3 replaceAll(SP<TextBufferView> const&, SelectionSet const&, slate::usubstring, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, unsigned int) + 543 (Sublime Text 2) [0x104be0dcf]
                      3 ??? (Sublime Text 2 + 1907152) [0x104be09d0]
                        3 TextBuffer::eraseCharacters(SelectionRegion) + 640 (Sublime Text 2) [0x104bd421c]
                          3 TokenStorage::eraseCharacters(SelectionRegion) + 1019 (Sublime Text 2) [0x104c46d49]
                            3 TokenStorage::tokenise(BucketContainer<tree_list<TokenBuffer, TokenBuffer::token_list_ops>, TokenStorage::TokenBufferFactory>::iterator, long long, LexerState*, slate::usubstring) + 547 (Sublime Text 2) [0x104c468a3]
                              2 TokenStorage::insertTokens(BucketContainer<tree_list<TokenBuffer, TokenBuffer::token_list_ops>, TokenStorage::TokenBufferFactory>::iterator, std::vector<TokenInfo, std::allocator<TokenInfo> >) + 468 (Sublime Text 2) [0x104c464b2]
                                2 memmove$VARIANT$sse42 + 228 (libsystem_c.dylib) [0x7fff92051aac]
                                 *2 hndl_alltraps + 225 (mach_kernel) [0xffffff80002ce411]
                                   *2 user_trap + 649 (mach_kernel) [0xffffff80002b7fa9]
                                     *1 vm_fault + 3634 (mach_kernel) [0xffffff8000262c62]
                                       *1 vm_page_wait + 185 (mach_kernel) [0xffffff8000287969]
                                         *1 thread_block_reason + 300 (mach_kernel) [0xffffff800022da0c]
                                           *1 ??? (mach_kernel + 190273) [0xffffff800022e741]
                                             *1 machine_switch_context + 366 (mach_kernel) [0xffffff80002b3d7e]
                                     *1 vm_fault + 2530 (mach_kernel) [0xffffff8000262812]
                                       *1 vm_page_alloc + 21 (mach_kernel) [0xffffff8000288715]
                                         *1 vm_page_grab + 482 (mach_kernel) [0xffffff8000287cf2]
                              1 TokenStorage::insertTokens(BucketContainer<tree_list<TokenBuffer, TokenBuffer::token_list_ops>, TokenStorage::TokenBufferFactory>::iterator, std::vector<TokenInfo, std::allocator<TokenInfo> >) + 560 (Sublime Text 2) [0x104c4650e]
                                1 Token::calculateWidth(UnicodeFont*) + 49 (Sublime Text 2) [0x104c28749]
                                  1 UnicodeFont::stringWidth(slate::usubstring) const + 51 (Sublime Text 2) [0x104c67deb]
                                    1 UnicodeFont::charWidth(wchar_t) const + 27 (Sublime Text 2) [0x104c69057]
                                      1 <executing in user space>
 *2 return_from_trap + 156 (mach_kernel) [0xffffff80002ce4bc]
   *2 i386_astintr + 35 (mach_kernel) [0xffffff80002b8163]
     *2 ast_taken + 209 (mach_kernel) [0xffffff800021b6e1]
       *2 bsd_ast + 839 (mach_kernel) [0xffffff8000568f17]
         *2 postsig_locked + 663 (mach_kernel) [0xffffff8000568a87]
           *2 exit1_internal + 567 (mach_kernel) [0xffffff8000556607]
             *2 task_terminate_internal + 435 (mach_kernel) [0xffffff8000235a53]
               *2 vm_map_remove + 80 (mach_kernel) [0xffffff800026a8f0]
                 *1 ??? (mach_kernel + 420748) [0xffffff8000266b8c]
                   *1 ??? (mach_kernel + 479680) [0xffffff80002751c0]
                     *1 ??? (mach_kernel + 482612) [0xffffff8000275d34]
                       *1 ??? (mach_kernel + 507463) [0xffffff800027be47]
                         *1 ??? (mach_kernel + 486629) [0xffffff8000276ce5]
                           *1 vm_page_free_prepare_object + 146 (mach_kernel) [0xffffff8000288c32]
                 *1 ??? (mach_kernel + 420380) [0xffffff8000266a1c]
                   *1 pmap_remove + 501 (mach_kernel) [0xffffff80002a2b65]
                     *1 pmap_remove_range + 364 (mach_kernel) [0xffffff80002a23ac]

  Thread 0xa7eef6   DispatchQueue 2          priority 48        
  3 _dispatch_mgr_thread + 54 (libdispatch.dylib) [0x7fff8fdef9ee]
    3 kevent + 10 (libsystem_kernel.dylib) [0x7fff90c3ad16]
     *3 ??? (mach_kernel + 3471600) [0xffffff800054f8f0]

  Thread 0xa7eef8   priority 46        
  3 thread_start + 13 (libsystem_c.dylib) [0x7fff92051181]
    3 _pthread_start + 327 (libsystem_c.dylib) [0x7fff92064742]
      3 ??? (Sublime Text 2 + 56745) [0x104a1cda9]
        3 thread_queue_runner::run() + 97 (Sublime Text 2) [0x104a1cf7b]
          3 __psynch_cvwait + 10 (libsystem_kernel.dylib) [0x7fff90c3a0fa]
           *3 psynch_cvcontinue + 0 (mach_kernel) [0xffffff80005b5d30]

  Thread 0xa7eef9   priority 46        
  3 thread_start + 13 (libsystem_c.dylib) [0x7fff92051181]
    3 _pthread_start + 327 (libsystem_c.dylib) [0x7fff92064742]
      3 ??? (Sublime Text 2 + 90745) [0x104a25279]
        3 io_worker::thread_proc() + 155 (Sublime Text 2) [0x104a25253]
          3 io_scheduler::extract_next_request() + 148 (Sublime Text 2) [0x104a25184]
            3 __psynch_cvwait + 10 (libsystem_kernel.dylib) [0x7fff90c3a0fa]
             *3 psynch_cvcontinue + 0 (mach_kernel) [0xffffff80005b5d30]

  Thread 0xa7eefa   priority 46        
  3 thread_start + 13 (libsystem_c.dylib) [0x7fff92051181]
    3 _pthread_start + 327 (libsystem_c.dylib) [0x7fff92064742]
      3 ??? (Sublime Text 2 + 90745) [0x104a25279]
        3 io_worker::thread_proc() + 155 (Sublime Text 2) [0x104a25253]
          3 io_scheduler::extract_next_request() + 148 (Sublime Text 2) [0x104a25184]
            3 __psynch_cvwait + 10 (libsystem_kernel.dylib) [0x7fff90c3a0fa]
             *3 psynch_cvcontinue + 0 (mach_kernel) [0xffffff80005b5d30]

  Thread 0xa82d66   priority 46        
 *3 ??? (mach_kernel + 3911792) [0xffffff80005bb070]

  Binary Images:
         0x104a0f000 -        0x104fbffef  com.sublimetext.2 Version 2.0.1, Build 2217 (2217) <EFE756CA-FF0C-3EEB-BA80-309F00040A5D> /Applications/Sublime Text 2.app/Contents/MacOS/Sublime Text 2
      0x7fff8fdeb000 -     0x7fff8fe00ff7  libdispatch.dylib <D26996BF-FC57-39EB-8829-F63585561E09> /usr/lib/system/libdispatch.dylib
      0x7fff90c28000 -     0x7fff90c43ff7  libsystem_kernel.dylib <C0535565-35D1-31A7-A744-63D9F10F12A4> /usr/lib/system/libsystem_kernel.dylib
      0x7fff92050000 -     0x7fff9211cfe7  libsystem_c.dylib <8CBCF9B9-EBB7-365E-A3FF-2F3850763C6B> /usr/lib/system/libsystem_c.dylib
      0x7fff98664000 -     0x7fff99291ff7  com.apple.AppKit 6.8 (1187.34) <1FF64844-EB62-3F96-AED7-6525B7CCEC23> /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit
 *0xffffff8000200000 - 0xffffff800074033c  mach_kernel <69A5853F-375A-3EF4-9247-478FD0247333> /mach_kernel
0 Likes

#2

I agree.
Looks like Replace All for new lines (\n) has issues. I tried with a list of only 6000+ email and it took over 5 minutes to replace! I tested this on another editor and it took only second.

Windows Sublime Text v2.0.1 build 2217 Find What: \n Replace With: ','

0 Likes