11/*
2- Copyright (c) 2018, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ Copyright (c) 2018, 2020 , Oracle and/or its affiliates. All rights reserved.
33
44 This program is free software; you can redistribute it and/or modify
55 it under the terms of the GNU General Public License, version 2.0,
@@ -531,11 +531,28 @@ ConfigSection::get_section_type_value()
531531 return val;
532532}
533533
534+ static bool
535+ compare_entry_key (ConfigSection::Entry *first,
536+ ConfigSection::Entry *second)
537+ {
538+ if (first == second)
539+ return false ;
540+ if (first->m_key < second->m_key )
541+ return true ;
542+ else if (first->m_key > second->m_key )
543+ return false ;
544+ /* Two entries should never have the same key */
545+ require (false );
546+ return false ;
547+ }
548+
534549Uint32
535550ConfigSection::get_v1_length () const
536551{
537552 check_magic ();
538- const ConfigSection *my_section = this ;
553+ // sorted entries in key key order
554+ std::vector<Entry *> sorted_entries (m_entry_array);
555+ std::sort (sorted_entries.begin (), sorted_entries.end (), compare_entry_key);
539556 ConfigSection *default_section = get_default_section ();
540557 Uint32 len = 0 ;
541558 Uint32 my_inx = 0 ;
@@ -553,32 +570,28 @@ ConfigSection::get_v1_length() const
553570 * key in an appropriate manner.
554571 */
555572 while (default_inx < default_section->m_num_entries ||
556- my_inx < my_section-> m_num_entries )
573+ my_inx < m_num_entries)
557574 {
558575 if ((default_inx >= default_section->m_num_entries ) ||
559- ((my_inx < my_section-> m_num_entries ) &&
560- (my_section-> m_entry_array [my_inx]->m_key <
576+ ((my_inx < m_num_entries) &&
577+ (sorted_entries [my_inx]->m_key <
561578 default_section->m_entry_array [default_inx]->m_key )))
562579
563580 {
564- len += my_section-> m_entry_array [my_inx]->get_v1_length ();
581+ len += sorted_entries [my_inx]->get_v1_length ();
565582 my_inx++;
566- }
567- else if ((my_inx >= my_section->m_num_entries ) ||
568- (my_section->m_entry_array [my_inx]->m_key >
569- default_section->m_entry_array [default_inx]->m_key ))
570- {
583+ } else if ((my_inx >= m_num_entries) ||
584+ (sorted_entries[my_inx]->m_key >
585+ default_section->m_entry_array [default_inx]->m_key )) {
571586 len += default_section->m_entry_array [default_inx]->get_v1_length ();
572587 default_inx++;
573- }
574- else
575- {
576- len += my_section->m_entry_array [my_inx]->get_v1_length ();
588+ } else {
589+ len += sorted_entries[my_inx]->get_v1_length ();
577590 my_inx++;
578591 default_inx++;
579592 }
580593 }
581- require (my_inx == my_section-> m_num_entries &&
594+ require (my_inx == m_num_entries &&
582595 default_inx == default_section->m_num_entries );
583596 /* *
584597 * Add two more entries for type of section and parent.
591604ConfigSection::create_v1_section (Uint32 **v1_ptr, Uint32 section_id)
592605{
593606 check_magic ();
594- ConfigSection *my_section = this ;
607+ // sorted entries in key key order
608+ std::vector<Entry*> sorted_entries (m_entry_array);
609+ std::sort (sorted_entries.begin (), sorted_entries.end (), compare_entry_key);
595610 ConfigSection *default_section = get_default_section ();
596611
597612 Uint32 my_inx = 0 ;
@@ -604,19 +619,19 @@ ConfigSection::create_v1_section(Uint32 **v1_ptr, Uint32 section_id)
604619 * holes in the array.
605620 */
606621 while (default_inx < default_section->m_num_entries ||
607- my_inx < my_section-> m_num_entries )
622+ my_inx < m_num_entries)
608623 {
609624 if ((default_inx >= default_section->m_num_entries ) ||
610- ((my_inx < my_section-> m_num_entries ) &&
611- (my_section-> m_entry_array [my_inx]->m_key <
625+ ((my_inx < m_num_entries) &&
626+ (sorted_entries [my_inx]->m_key <
612627 default_section->m_entry_array [default_inx]->m_key )))
613628 {
614- Entry *my_entry = my_section-> m_entry_array [my_inx];
629+ Entry *my_entry = sorted_entries [my_inx];
615630 my_entry->create_v1_entry (v1_ptr, section_id);
616631 my_inx++;
617632 }
618- else if ((my_inx >= my_section-> m_num_entries ) ||
619- (my_section-> m_entry_array [my_inx]->m_key >
633+ else if ((my_inx >= m_num_entries) ||
634+ (sorted_entries [my_inx]->m_key >
620635 default_section->m_entry_array [default_inx]->m_key ))
621636 {
622637 Entry *default_entry = default_section->m_entry_array [default_inx];
@@ -625,13 +640,13 @@ ConfigSection::create_v1_section(Uint32 **v1_ptr, Uint32 section_id)
625640 }
626641 else
627642 {
628- Entry *my_entry = my_section-> m_entry_array [my_inx];
643+ Entry *my_entry = sorted_entries [my_inx];
629644 my_entry->create_v1_entry (v1_ptr, section_id);
630645 my_inx++;
631646 default_inx++;
632647 }
633648 }
634- require (my_inx == my_section-> m_num_entries &&
649+ require (my_inx == m_num_entries &&
635650 default_inx == default_section->m_num_entries );
636651 {
637652 /* *
@@ -1113,21 +1128,6 @@ ConfigSection::handle_default_section(ConfigSection *default_section)
11131128 sort ();
11141129}
11151130
1116- static bool
1117- compare_entry_key (ConfigSection::Entry *first,
1118- ConfigSection::Entry *second)
1119- {
1120- if (first == second)
1121- return false ;
1122- if (first->m_key < second->m_key )
1123- return true ;
1124- else if (first->m_key > second->m_key )
1125- return false ;
1126- /* Two entries should never have the same key */
1127- require (false );
1128- return false ;
1129- }
1130-
11311131void
11321132ConfigSection::sort ()
11331133{
0 commit comments