Source

libphonenumber-csharp / cpp / src / phonenumbers / geocoding / area_code_map.cc

Diff from to

cpp/src/phonenumbers/geocoding/area_code_map.cc

 #include "phonenumbers/geocoding/area_code_map.h"
 
 #include <cstddef>
-#include <iterator>
-#include <set>
 
-#include "phonenumbers/geocoding/area_code_map_storage_strategy.h"
 #include "phonenumbers/geocoding/default_map_storage.h"
 #include "phonenumbers/phonenumber.pb.h"
 #include "phonenumbers/phonenumberutil.h"
 AreaCodeMap::~AreaCodeMap() {
 }
 
-AreaCodeMapStorageStrategy* AreaCodeMap::CreateDefaultMapStorage() const {
-  return new DefaultMapStorage();
-}
-
-void AreaCodeMap::ReadAreaCodeMap(const map<int, string>& area_codes) {
-  AreaCodeMapStorageStrategy* storage = CreateDefaultMapStorage();
-  storage->ReadFromMap(area_codes);
+void AreaCodeMap::ReadAreaCodeMap(const PrefixDescriptions* descriptions) {
+  DefaultMapStorage* storage = new DefaultMapStorage();
+  storage->ReadFromMap(descriptions);
   storage_.reset(storage);
 }
 
-const string* AreaCodeMap::Lookup(const PhoneNumber& number) const {
+const char* AreaCodeMap::Lookup(const PhoneNumber& number) const {
   const int entries = storage_->GetNumOfEntries();
   if (!entries) {
     return NULL;
   safe_strto64(SimpleItoa(number.country_code()) + national_number,
                &phone_prefix);
 
-  const set<int>& lengths = storage_->GetPossibleLengths();
+  const int* const lengths = storage_->GetPossibleLengths();
+  const int lengths_size = storage_->GetPossibleLengthsSize();
   int current_index = entries - 1;
-  for (set<int>::const_reverse_iterator lengths_it = lengths.rbegin();
-       lengths_it != lengths.rend(); ++lengths_it) {
-    const int possible_length = *lengths_it;
+  for (int lengths_index = lengths_size - 1; lengths_index >= 0;
+       --lengths_index) {
+    const int possible_length = lengths[lengths_index];
     string phone_prefix_str = SimpleItoa(phone_prefix);
     if (static_cast<int>(phone_prefix_str.length()) > possible_length) {
       safe_strto64(phone_prefix_str.substr(0, possible_length), &phone_prefix);
     if (current_index < 0) {
       return NULL;
     }
-    const int current_prefix = storage_->GetPrefix(current_index);
+    const int32 current_prefix = storage_->GetPrefix(current_index);
     if (phone_prefix == current_prefix) {
-      return &storage_->GetDescription(current_index);
+      return storage_->GetDescription(current_index);
     }
   }
   return NULL;
   int current = 0;
   while (start <= end) {
     current = (start + end) / 2;
-    int current_value = storage_->GetPrefix(current);
+    int32 current_value = storage_->GetPrefix(current);
     if (current_value == value) {
       return current;
     } else if (current_value > value) {