Skip to content

Commit

Permalink
Moves MessageFactory instantation to module-level private.
Browse files Browse the repository at this point in the history
Avoids costly redudant work when parsing FHIR json.

PiperOrigin-RevId: 335684550
  • Loading branch information
Cameron Tew authored and nickgeorge committed Oct 6, 2020
1 parent 1480c73 commit 2c1dcb4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions py/google/fhir/utils/proto_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from google.protobuf import message
from google.protobuf import message_factory

_factory = message_factory.MessageFactory()

MessageOrDescriptorBase = Union[descriptor_pb2.DescriptorProto, message.Message,
descriptor.DescriptorBase]

Expand Down Expand Up @@ -270,8 +272,7 @@ def set_in_parent_or_add(
def get_message_class_from_descriptor(
desc: descriptor.Descriptor) -> Type[message.Message]:
"""Returns the class of the message type corresponding to the descriptor."""
factory = message_factory.MessageFactory()
return factory.GetPrototype(desc)
return _factory.GetPrototype(desc)


def create_message_from_descriptor(desc: descriptor.Descriptor,
Expand Down

0 comments on commit 2c1dcb4

Please sign in to comment.