Repository: apache/arrow
File: cpp/src/parquet/types.cc (C++)

Code before:
  return type.str();
}

std::string LogicalType::Impl::Variant::ToJSON() const {
  std::stringstream json;
  json << R"({"Type": "Variant", "SpecVersion": )" << static_cast<int>(specVersion_)
       << "}";

  return json.str();
}

format::LogicalType LogicalType::Impl::Variant::ToThrift() const {
  format::LogicalType type;
  format::VariantType variant_type;
  variant_type.__set_specification_version(specVersion_);
  type.__set_VARIANT(variant_type);
  return type;
}

std::shared_ptr<const LogicalType> VariantLogicalType::Make(const int8_t specVersion) {
  auto logical_type = std::shared_ptr<VariantLogicalType>(new VariantLogicalType());
  logical_type->impl_.reset(new LogicalType::Impl::Variant(specVersion));
  return logical_type;
}

class LogicalType::Impl::No final : public LogicalType::Impl::SimpleCompatible,
                                    public LogicalType::Impl::UniversalApplicable {
 public:
  friend class NoLogicalType;

  OVERRIDE_TOSTRING(None)

 private:
  No()
      : LogicalType::Impl(LogicalType::Type::NONE, SortOrder::UNKNOWN),
        LogicalType::Impl::SimpleCompatible(ConvertedType::NONE) {}
};

GENERATE_MAKE(No)

class LogicalType::Impl::Undefined final : public LogicalType::Impl::SimpleCompatible,
                                           public LogicalType::Impl::UniversalApplicable {
 public:
  friend class UndefinedLogicalType;

  OVERRIDE_TOSTRING(Undefined)

 private:
  Undefined()
      : LogicalType::Impl(LogicalType::Type::UNDEFINED, SortOrder::UNKNOWN),
        LogicalType::Impl::SimpleCompatible(ConvertedType::UNDEFINED) {}

Review comment (performance):
Can we use `std::make_shared`? It's more terse _and_ more efficient.

Code after:
}

std::string LogicalType::Impl::Variant::ToString() const {
  std::stringstream type;
  type << "Variant(" << static_cast<int>(spec_version_) << ")";
  return type.str();
}

std::string LogicalType::Impl::Variant::ToJSON() const {
  std::stringstream json;
  json << R"({"Type": "Variant", "SpecVersion": )" << static_cast<int>(spec_version_)
       << "}";

  return json.str();
}

format::LogicalType LogicalType::Impl::Variant::ToThrift() const {
  format::LogicalType type;
  format::VariantType variant_type;
  variant_type.__set_specification_version(spec_version_);
  type.__set_VARIANT(variant_type);
  return type;
}

std::shared_ptr<const LogicalType> VariantLogicalType::Make(const int8_t spec_version) {
  auto logical_type = std::shared_ptr<VariantLogicalType>(new VariantLogicalType());
  logical_type->impl_.reset(new LogicalType::Impl::Variant(spec_version));
  return logical_type;
}

class LogicalType::Impl::No final : public LogicalType::Impl::SimpleCompatible,
                                    public LogicalType::Impl::UniversalApplicable {
 public:
  friend class NoLogicalType;

  OVERRIDE_TOSTRING(None)

 private:
  No()
      : LogicalType::Impl(LogicalType::Type::NONE, SortOrder::UNKNOWN),
        LogicalType::Impl::SimpleCompatible(ConvertedType::NONE) {}
};

GENERATE_MAKE(No)

class LogicalType::Impl::Undefined final : public LogicalType::Impl::SimpleCompatible,
                                           public LogicalType::Impl::UniversalApplicable {
 public:
  friend class UndefinedLogicalType;

  OVERRIDE_TOSTRING(Undefined)