comparison OrthancServer/OrthancRestApi/OrthancRestApi.cpp @ 3841:be7df7fe3d80

avoid one memcpy of the DICOM buffer on "POST /instances"
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 16 Apr 2020 16:58:37 +0200
parents 2a170a8f1faf
children 44bfcfdf42e8
comparison
equal deleted inserted replaced
3840:e7003b2203a7 3841:be7df7fe3d80
119 { 119 {
120 throw OrthancException(ErrorCode_BadFileFormat, 120 throw OrthancException(ErrorCode_BadFileFormat,
121 "Received an empty DICOM file"); 121 "Received an empty DICOM file");
122 } 122 }
123 123
124 // The lifetime of "dicom" must be longer than "toStore", as the
125 // latter can possibly store a reference to the former (*)
124 std::string dicom; 126 std::string dicom;
127
128 DicomInstanceToStore toStore;
129 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
125 130
126 if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip")) 131 if (boost::iequals(call.GetHttpHeader("content-encoding", ""), "gzip"))
127 { 132 {
128 GzipCompressor compressor; 133 GzipCompressor compressor;
129 compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize()); 134 compressor.Uncompress(dicom, call.GetBodyData(), call.GetBodySize());
135 toStore.SetBuffer(dicom.c_str(), dicom.size()); // (*)
130 } 136 }
131 else 137 else
132 { 138 {
133 // TODO Remove unneccessary memcpy 139 toStore.SetBuffer(call.GetBodyData(), call.GetBodySize());
134 call.BodyToString(dicom); 140 }
135 }
136
137 DicomInstanceToStore toStore;
138 toStore.SetOrigin(DicomInstanceOrigin::FromRest(call));
139 toStore.SetBuffer(dicom);
140 141
141 std::string publicId; 142 std::string publicId;
142 StoreStatus status = context.Store(publicId, toStore); 143 StoreStatus status = context.Store(publicId, toStore);
143 144
144 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status); 145 OrthancRestApi::GetApi(call).AnswerStoredInstance(call, toStore, status);