Repository: microsoft/onnxruntime
File: onnxruntime/core/providers/vitisai/imp/global_api.cc (C++)

Code before:
 private:
  void* handle_{};
};

static OrtVitisAIEpAPI s_library_vitisaiep;
static std::shared_ptr<KernelRegistry> s_kernel_registry_vitisaiep;
static std::vector<OrtCustomOpDomain*> s_domains_vitisaiep;
static vaip_core::OrtApiForVaip the_global_api;
std::shared_ptr<KernelRegistry> get_kernel_registry_vitisaiep() { return s_kernel_registry_vitisaiep; }
const std::vector<OrtCustomOpDomain*>& get_domains_vitisaiep() { return s_domains_vitisaiep; }

void profiler_collect(
    std::vector<EventInfo>& api_events,
    std::vector<EventInfo>& kernel_events) {
  if (s_library_vitisaiep.profiler_collect) {
    s_library_vitisaiep.profiler_collect(api_events, kernel_events);
  }
}

std::string get_compiled_model_compatibility_info(
    const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
    const onnxruntime::GraphViewer& graph_viewer) {
  if (s_library_vitisaiep.get_compiled_model_compatibility_info) {
    const char* result = s_library_vitisaiep.get_compiled_model_compatibility_info(&eps, &graph_viewer);
    if (result && result[0] != '\0') {
      return std::string(result);
    }
  }
  return std::string();
}

Status validate_compiled_model_compatibility_info(
    const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
    const std::string& compatibility_info,
    OrtCompiledModelCompatibility& model_compatibility) {
  if (s_library_vitisaiep.validate_compiled_model_compatibility_info) {
    // Call with nullptr devices since ORT provider doesn't have device information
    int ret_model_compatibility = 0;
    int status = s_library_vitisaiep.validate_compiled_model_compatibility_info(
        &eps,
        compatibility_info.c_str(),
        nullptr,  // devices - not available
        0,        // num_devices
        &ret_model_compatibility);
    if (status == 0) {
      model_compatibility = static_cast<OrtCompiledModelCompatibility>(ret_model_compatibility);
      return Status::OK();
    }
  }
  // Default to NOT_APPLICABLE
  model_compatibility = OrtCompiledModelCompatibility_EP_NOT_APPLICABLE;

Review comment (suggestion):
>return std::string(result); [](http://example.com/codeflow?start=6&length=27)

suggest NRVO applied here for better readability.
Declare empty string on the outset. .assign(result) when not empty and and the end do a single return.

Code after:
 private:
  void* handle_{};
};

static OrtVitisAIEpAPI s_library_vitisaiep;
static std::shared_ptr<KernelRegistry> s_kernel_registry_vitisaiep;
static std::vector<OrtCustomOpDomain*> s_domains_vitisaiep;
static vaip_core::OrtApiForVaip the_global_api;
std::shared_ptr<KernelRegistry> get_kernel_registry_vitisaiep() { return s_kernel_registry_vitisaiep; }
const std::vector<OrtCustomOpDomain*>& get_domains_vitisaiep() { return s_domains_vitisaiep; }

void profiler_collect(
    std::vector<EventInfo>& api_events,
    std::vector<EventInfo>& kernel_events) {
  if (s_library_vitisaiep.profiler_collect) {
    s_library_vitisaiep.profiler_collect(api_events, kernel_events);
  }
}

std::string get_compiled_model_compatibility_info(
    const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
    const onnxruntime::GraphViewer& graph_viewer) {
  std::string result_str;
  if (s_library_vitisaiep.get_compiled_model_compatibility_info) {
    const char* result = s_library_vitisaiep.get_compiled_model_compatibility_info(&eps, &graph_viewer);
    if (result && result[0] != '\0') {
      result_str = result;
    }
  }
  return result_str;
}

Status validate_compiled_model_compatibility_info(
    const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
    const std::string& compatibility_info,
    OrtCompiledModelCompatibility& model_compatibility) {
  if (s_library_vitisaiep.validate_compiled_model_compatibility_info) {
    // Call with nullptr devices since ORT provider doesn't have device information
    int ret_model_compatibility = 0;
    int status = s_library_vitisaiep.validate_compiled_model_compatibility_info(
        &eps,
        compatibility_info.c_str(),
        nullptr,  // devices - not available
        0,        // num_devices
        &ret_model_compatibility);
    if (status == 0) {
      model_compatibility = static_cast<OrtCompiledModelCompatibility>(ret_model_compatibility);
      return Status::OK();
    }
  }
  // Default to NOT_APPLICABLE