Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ceecbfc4 authored by Tom Cherry's avatar Tom Cherry Committed by Gerrit Code Review
Browse files

Merge "Rename property 'schema' to 'type'"

parents 55feb241 4094e5ee
Loading
Loading
Loading
Loading
+15 −16
Original line number Diff line number Diff line
@@ -32,8 +32,8 @@ struct PropertyEntry {

  // This is the context match for this node_; ~0u if it doesn't correspond to any.
  uint32_t context_index;
  // This is the schema for this node_; ~0u if it doesn't correspond to any.
  uint32_t schema_index;
  // This is the type for this node_; ~0u if it doesn't correspond to any.
  uint32_t type_index;
};

struct TrieNodeInternal {
@@ -61,7 +61,7 @@ struct PropertyInfoAreaHeader {
  uint32_t minimum_supported_version;
  uint32_t size;
  uint32_t contexts_offset;
  uint32_t schemas_offset;
  uint32_t types_offset;
  uint32_t root_offset;
};

@@ -103,7 +103,7 @@ class TrieNode {
  }

  uint32_t context_index() const { return node_property_entry()->context_index; }
  uint32_t schema_index() const { return node_property_entry()->schema_index; }
  uint32_t type_index() const { return node_property_entry()->type_index; }

  uint32_t num_child_nodes() const { return trie_node_base_->num_child_nodes; }
  TrieNode child_node(int n) const {
@@ -143,12 +143,11 @@ class TrieNode {

class PropertyInfoArea : private SerializedData {
 public:
  void GetPropertyInfoIndexes(const char* name, uint32_t* context_index,
                              uint32_t* schema_index) const;
  void GetPropertyInfo(const char* property, const char** context, const char** schema) const;
  void GetPropertyInfoIndexes(const char* name, uint32_t* context_index, uint32_t* type_index) const;
  void GetPropertyInfo(const char* property, const char** context, const char** type) const;

  int FindContextIndex(const char* context) const;
  int FindSchemaIndex(const char* schema) const;
  int FindTypeIndex(const char* type) const;

  const char* context(uint32_t index) const {
    uint32_t context_array_size_offset = contexts_offset();
@@ -156,10 +155,10 @@ class PropertyInfoArea : private SerializedData {
    return data_base() + context_array[index];
  }

  const char* schema(uint32_t index) const {
    uint32_t schema_array_size_offset = schemas_offset();
    const uint32_t* schema_array = uint32_array(schema_array_size_offset + sizeof(uint32_t));
    return data_base() + schema_array[index];
  const char* type(uint32_t index) const {
    uint32_t type_array_size_offset = types_offset();
    const uint32_t* type_array = uint32_array(type_array_size_offset + sizeof(uint32_t));
    return data_base() + type_array[index];
  }

  uint32_t current_version() const { return header()->current_version; }
@@ -168,21 +167,21 @@ class PropertyInfoArea : private SerializedData {
  uint32_t size() const { return SerializedData::size(); }

  uint32_t num_contexts() const { return uint32_array(contexts_offset())[0]; }
  uint32_t num_schemas() const { return uint32_array(schemas_offset())[0]; }
  uint32_t num_types() const { return uint32_array(types_offset())[0]; }

  TrieNode root_node() const { return trie(header()->root_offset); }

 private:
  void CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node,
                        uint32_t* context_index, uint32_t* schema_index) const;
                        uint32_t* context_index, uint32_t* type_index) const;

  const PropertyInfoAreaHeader* header() const {
    return reinterpret_cast<const PropertyInfoAreaHeader*>(data_base());
  }
  uint32_t contexts_offset() const { return header()->contexts_offset; }
  uint32_t contexts_array_offset() const { return contexts_offset() + sizeof(uint32_t); }
  uint32_t schemas_offset() const { return header()->schemas_offset; }
  uint32_t schemas_array_offset() const { return schemas_offset() + sizeof(uint32_t); }
  uint32_t types_offset() const { return header()->types_offset; }
  uint32_t types_array_offset() const { return types_offset() + sizeof(uint32_t); }

  TrieNode trie(uint32_t offset) const {
    if (offset != 0 && offset > size()) return TrieNode();
+26 −26
Original line number Diff line number Diff line
@@ -56,12 +56,12 @@ int PropertyInfoArea::FindContextIndex(const char* context) const {
  });
}

// Binary search the list of schemas to find the index of a given schema string.
// Binary search the list of types to find the index of a given type string.
// Only should be used for TrieSerializer to construct the Trie.
int PropertyInfoArea::FindSchemaIndex(const char* schema) const {
  return Find(num_schemas(), [this, schema](auto array_offset) {
    auto string_offset = uint32_array(schemas_array_offset())[array_offset];
    return strcmp(c_string(string_offset), schema);
int PropertyInfoArea::FindTypeIndex(const char* type) const {
  return Find(num_types(), [this, type](auto array_offset) {
    auto string_offset = uint32_array(types_array_offset())[array_offset];
    return strcmp(c_string(string_offset), type);
  });
}

@@ -89,7 +89,7 @@ bool TrieNode::FindChildForString(const char* name, uint32_t namelen, TrieNode*
}

void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNode& trie_node,
                                        uint32_t* context_index, uint32_t* schema_index) const {
                                        uint32_t* context_index, uint32_t* type_index) const {
  const uint32_t remaining_name_size = strlen(remaining_name);
  for (uint32_t i = 0; i < trie_node.num_prefixes(); ++i) {
    auto prefix_len = trie_node.prefix(i)->namelen;
@@ -99,8 +99,8 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo
      if (trie_node.prefix(i)->context_index != ~0u) {
        *context_index = trie_node.prefix(i)->context_index;
      }
      if (trie_node.prefix(i)->schema_index != ~0u) {
        *schema_index = trie_node.prefix(i)->schema_index;
      if (trie_node.prefix(i)->type_index != ~0u) {
        *type_index = trie_node.prefix(i)->type_index;
      }
      return;
    }
@@ -108,9 +108,9 @@ void PropertyInfoArea::CheckPrefixMatch(const char* remaining_name, const TrieNo
}

void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* context_index,
                                              uint32_t* schema_index) const {
                                              uint32_t* type_index) const {
  uint32_t return_context_index = ~0u;
  uint32_t return_schema_index = ~0u;
  uint32_t return_type_index = ~0u;
  const char* remaining_name = name;
  auto trie_node = root_node();
  while (true) {
@@ -120,13 +120,13 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex
    if (trie_node.context_index() != ~0u) {
      return_context_index = trie_node.context_index();
    }
    if (trie_node.schema_index() != ~0u) {
      return_schema_index = trie_node.schema_index();
    if (trie_node.type_index() != ~0u) {
      return_type_index = trie_node.type_index();
    }

    // Check prefixes at this node.  This comes after the node check since these prefixes are by
    // definition longer than the node itself.
    CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_schema_index);
    CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_type_index);

    if (sep == nullptr) {
      break;
@@ -153,29 +153,29 @@ void PropertyInfoArea::GetPropertyInfoIndexes(const char* name, uint32_t* contex
          *context_index = return_context_index;
        }
      }
      if (schema_index != nullptr) {
        if (trie_node.exact_match(i)->schema_index != ~0u) {
          *schema_index = trie_node.exact_match(i)->schema_index;
      if (type_index != nullptr) {
        if (trie_node.exact_match(i)->type_index != ~0u) {
          *type_index = trie_node.exact_match(i)->type_index;
        } else {
          *schema_index = return_schema_index;
          *type_index = return_type_index;
        }
      }
      return;
    }
  }
  // Check prefix matches for prefixes not deliminated with '.'
  CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_schema_index);
  CheckPrefixMatch(remaining_name, trie_node, &return_context_index, &return_type_index);
  // Return previously found prefix match.
  if (context_index != nullptr) *context_index = return_context_index;
  if (schema_index != nullptr) *schema_index = return_schema_index;
  if (type_index != nullptr) *type_index = return_type_index;
  return;
}

void PropertyInfoArea::GetPropertyInfo(const char* property, const char** context,
                                       const char** schema) const {
                                       const char** type) const {
  uint32_t context_index;
  uint32_t schema_index;
  GetPropertyInfoIndexes(property, &context_index, &schema_index);
  uint32_t type_index;
  GetPropertyInfoIndexes(property, &context_index, &type_index);
  if (context != nullptr) {
    if (context_index == ~0u) {
      *context = nullptr;
@@ -183,11 +183,11 @@ void PropertyInfoArea::GetPropertyInfo(const char* property, const char** contex
      *context = this->context(context_index);
    }
  }
  if (schema != nullptr) {
    if (schema_index == ~0u) {
      *schema = nullptr;
  if (type != nullptr) {
    if (type_index == ~0u) {
      *type = nullptr;
    } else {
      *schema = this->schema(schema_index);
      *type = this->type(type_index);
    }
  }
}
+4 −4
Original line number Diff line number Diff line
@@ -26,19 +26,19 @@ namespace properties {
struct PropertyInfoEntry {
  PropertyInfoEntry() {}
  template <typename T, typename U, typename V>
  PropertyInfoEntry(T&& name, U&& context, V&& schema, bool exact_match)
  PropertyInfoEntry(T&& name, U&& context, V&& type, bool exact_match)
      : name(std::forward<T>(name)),
        context(std::forward<U>(context)),
        schema(std::forward<V>(schema)),
        type(std::forward<V>(type)),
        exact_match(exact_match) {}
  std::string name;
  std::string context;
  std::string schema;
  std::string type;
  bool exact_match;
};

bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info,
               const std::string& default_context, const std::string& default_schema,
               const std::string& default_context, const std::string& default_type,
               std::string* serialized_trie, std::string* error);

void ParsePropertyInfoFile(const std::string& file_contents,
+2 −2
Original line number Diff line number Diff line
@@ -28,9 +28,9 @@ bool ParsePropertyInfoLine(const std::string& line, PropertyInfoEntry* out, std:

  // It is not an error to not find these, as older files will not contain them.
  auto exact_match = tokenizer.GetNext();
  auto schema = tokenizer.GetRemaining();
  auto type = tokenizer.GetRemaining();

  *out = {property, context, schema, exact_match == "exact"};
  *out = {property, context, type, exact_match == "exact"};
  return true;
}

+4 −4
Original line number Diff line number Diff line
@@ -27,13 +27,13 @@ namespace android {
namespace properties {

bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info,
               const std::string& default_context, const std::string& default_schema,
               const std::string& default_context, const std::string& default_type,
               std::string* serialized_trie, std::string* error) {
  // Check that names are legal first
  auto trie_builder = TrieBuilder(default_context, default_schema);
  auto trie_builder = TrieBuilder(default_context, default_type);

  for (const auto& [name, context, schema, is_exact] : property_info) {
    if (!trie_builder.AddToTrie(name, context, schema, is_exact, error)) {
  for (const auto& [name, context, type, is_exact] : property_info) {
    if (!trie_builder.AddToTrie(name, context, type, is_exact, error)) {
      return false;
    }
  }
Loading