@@ -483,16 +483,15 @@ void ekg::utf8_concat(
483483}
484484
485485void ekg::text::swizzle (
486- size_t chunk_index ,
486+ std::list<ekg::io:: chunk_t >::iterator chunk_it ,
487487 size_t line_index,
488488 std::vector<std::string> &to_swizzle,
489489 bool skip_first_line
490490) {
491491 this ->was_audited = true ;
492-
493492 bool is_empty {to_swizzle.empty ()};
494- ekg::io::chunk_t &chunk {this ->loaded_chunks .at (chunk_index)};
495493
494+ ekg::io::chunk_t &chunk {*chunk_it};
496495 if (skip_first_line) {
497496 chunk.at (line_index) = is_empty ? " " : to_swizzle.at (0 );
498497 }
@@ -528,18 +527,20 @@ void ekg::text::swizzle(
528527
529528 for (size_t jt {}; jt < newly_chunks; jt++) {
530529 this ->loaded_chunks .insert (
531- this -> loaded_chunks . begin () + chunk_index + jt + 1 ,
530+ chunk_it ,
532531 ekg::io::chunk_t {
533532 to_swizzle_chunk.begin () + (this ->lines_per_chunk_limit * (jt + 0 )),
534533 to_swizzle_chunk.begin () + (this ->lines_per_chunk_limit * (jt + 1 ))
535534 }
536535 );
536+
537+ chunk_it++;
537538 }
538539
539540 size_t rest {to_swizzle_chunk_size - (this ->lines_per_chunk_limit * newly_chunks)};
540541 if (rest > 0 ) {
541542 this ->loaded_chunks .insert (
542- this -> loaded_chunks . begin () + chunk_index + newly_chunks + 1 ,
543+ chunk_it ,
543544 ekg::io::chunk_t {
544545 to_swizzle_chunk.begin () + (this ->lines_per_chunk_limit * (newly_chunks + 0 )),
545546 to_swizzle_chunk.end ()
@@ -561,8 +562,8 @@ size_t ekg::text::set(size_t index, std::string_view line, ekg::io::chunk_t &spl
561562 ekg::utf8_split_endings (line, split_endings);
562563
563564 bool ok {};
564- for (size_t it {}; it < this ->loaded_chunks .size (); it++) {
565- ekg::io::chunk_t &chunk {this -> loaded_chunks . at (it) };
565+ for (std::list<ekg::io:: chunk_t >::iterator it {this -> loaded_chunks . begin () }; it != this ->loaded_chunks .end (); it++) {
566+ ekg::io::chunk_t &chunk {*it };
566567
567568 previous_lines = current_lines;
568569 current_lines += (chunk_size = chunk.size ());
@@ -591,8 +592,8 @@ std::string ekg::text::at(size_t index) {
591592 size_t previous_lines {};
592593 size_t chunk_size {};
593594
594- for (size_t it {}; it < chunks_size ; it++) {
595- ekg::io::chunk_t &chunk {this -> loaded_chunks . at (it) };
595+ for (std::list<ekg::io:: chunk_t >::iterator it {this -> loaded_chunks . begin () }; it != this -> loaded_chunks . end () ; it++) {
596+ ekg::io::chunk_t &chunk {*it };
596597 previous_lines = current_lines;
597598 current_lines += (chunk_size = chunk.size ());
598599
@@ -632,8 +633,8 @@ void ekg::text::insert(
632633 }
633634
634635 size_t total_of_chunks {this ->loaded_chunks .size ()};
635- for (size_t it {}; it < total_of_chunks ; it++) {
636- ekg::io::chunk_t &chunk {this -> loaded_chunks . at (it) };
636+ for (std::list<ekg::io:: chunk_t >::iterator it {this -> loaded_chunks . begin () }; it != this -> loaded_chunks . end () ; it++) {
637+ ekg::io::chunk_t &chunk {*it };
637638
638639 previous_lines = current_lines;
639640 current_lines += (chunk_size = chunk.size ());
@@ -681,8 +682,8 @@ std::string ekg::text::read(
681682 bool oka_end {};
682683
683684 std::string builder {};
684- for (size_t it {}; it < total_of_chunks ; it++) {
685- ekg::io::chunk_t &chunk {this -> loaded_chunks . at (it) };
685+ for (std::list<ekg::io:: chunk_t >::iterator it {this -> loaded_chunks . begin () }; it != this -> loaded_chunks . end () ; it++) {
686+ ekg::io::chunk_t &chunk {*it };
686687
687688 previous_lines = current_lines;
688689 current_lines += (chunk_size = chunk.size ());
@@ -767,8 +768,8 @@ void ekg::text::erase(
767768 bool empty_chunk {};
768769 bool goto_next_chunk {};
769770
770- for (size_t it {}; it < this ->loaded_chunks .size (); it++) {
771- ekg::io::chunk_t &chunk {this -> loaded_chunks . at (it) };
771+ for (std::list<ekg::io:: chunk_t >::iterator it {this -> loaded_chunks . begin () }; it != this ->loaded_chunks .end (); it++) {
772+ ekg::io::chunk_t &chunk {*it };
772773
773774 previous_lines = lines;
774775 lines += (chunk_size = chunk.size ());
@@ -778,7 +779,7 @@ void ekg::text::erase(
778779 begin = begin - previous_lines;
779780
780781 while (remains_lines != 0 ) {
781- ekg::io::chunk_t &chunk {this -> loaded_chunks . at (it) };
782+ ekg::io::chunk_t &chunk {*it };
782783
783784 chunk_size = chunk.size ();
784785 goto_next_chunk = begin + remains_lines > chunk.size ();
@@ -791,12 +792,12 @@ void ekg::text::erase(
791792 empty_chunk = chunk.empty ();
792793 if (empty_chunk) {
793794 this ->loaded_chunks .erase (
794- this -> loaded_chunks . begin () + it
795+ it
795796 );
796797 }
797798
798799 if (goto_next_chunk) {
799- it += !empty_chunk;
800+ if ( !empty_chunk) it++ ;
800801 remains_lines -= chunk_size - begin;
801802 begin = 0 ;
802803 continue ;
@@ -819,23 +820,24 @@ void ekg::text::push_back(std::string_view line) {
819820
820821 if (this ->loaded_chunks .empty ()) {
821822 this ->loaded_chunks .emplace_back ().emplace_back ();
822- this ->swizzle (0 , 0 , splitted, true );
823+ this ->swizzle (this -> loaded_chunks . begin () , 0 , splitted, true );
823824 return ;
824825 }
825826
827+ std::list<ekg::io::chunk_t >::iterator last_it {--this ->loaded_chunks .end ()};
826828 ekg::io::chunk_t &last_chunk {
827- this -> loaded_chunks . back ()
829+ *last_it
828830 };
829831
830832 this ->swizzle (
831- this -> loaded_chunks . size () - 1 ,
833+ last_it ,
832834 last_chunk.size () - !last_chunk.empty (),
833835 splitted,
834836 false
835837 );
836838}
837839
838- std::vector <ekg::io::chunk_t > &ekg::text::chunks_data () {
840+ std::list <ekg::io::chunk_t > &ekg::text::chunks_data () {
839841 return this ->loaded_chunks ;
840842}
841843
0 commit comments