<commit_before>module MongoModel
  module Attributes
    module Mongo
      def to_mongo
        inject({}) do |result, (k, v)|
          property = properties[k]
          
          if property
            result[property.as] = property.to_mongo(v)
          else
            converter = Types.converter_for(v.class)
            result[k.to_s] = converter.to_mongo(v)
          end
          
          result
        end
      end
      
      def load!(hash)
        from_mongo!(hash)
      end
      
      def from_mongo!(hash)
        hash.each do |k, v|
          property = properties_as[k.to_s]
          
          if property
            child = self[property.name] = property.from_mongo(v)
            child.parent_document = instance if child.respond_to?(:parent_document=)
          else
            self[k.to_sym] = v
          end<commit_msg>Performance improvement: don't typecast when loading from db<commit_after>module MongoModel
  module Attributes
    module Mongo
      def to_mongo
        inject({}) do |result, (k, v)|
          property = properties[k]
          
          if property
            result[property.as] = property.to_mongo(v)
          else
            converter = Types.converter_for(v.class)
            result[k.to_s] = converter.to_mongo(v)
          end
          
          result
        end
      end
      
      def load!(hash)
        from_mongo!(hash)
      end
      
      def from_mongo!(hash)
        hash.each do |k, v|
          property = properties_as[k.to_s]
          
          if property
            child = store(property.name, property.from_mongo(v))
            child.parent_document = instance if child.respond_to?(:parent_document=)
          else
            self[k.to_sym] = v
          end
{'fraction_non_alphanumeric': 0.08271954674220963, 'fraction_numerical': 0.0, 'mean_word_length': 1.4908321579689703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3726964', 'n_tokens_mistral': 518, 'n_tokens_neox': 509, 'n_words': 112}