Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Side by Side Diff: src/wasm/wasm-result.h

Issue 2173403002: Replace SmartArrayPointer<T> with unique_ptr<T[]> (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: even less redness Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_WASM_RESULT_H_ 5 #ifndef V8_WASM_RESULT_H_
6 #define V8_WASM_RESULT_H_ 6 #define V8_WASM_RESULT_H_
7 7
8 #include <memory>
9
8 #include "src/base/compiler-specific.h" 10 #include "src/base/compiler-specific.h"
9 #include "src/base/smart-pointers.h" 11 #include "src/base/smart-pointers.h"
10 12
11 #include "src/handles.h" 13 #include "src/handles.h"
12 #include "src/globals.h" 14 #include "src/globals.h"
13 15
14 namespace v8 { 16 namespace v8 {
15 namespace internal { 17 namespace internal {
16 18
17 class Isolate; 19 class Isolate;
(...skipping 15 matching lines...) Expand all
33 kInvalidLocalIndex, // invalid local 35 kInvalidLocalIndex, // invalid local
34 kInvalidGlobalIndex, // invalid global 36 kInvalidGlobalIndex, // invalid global
35 kInvalidFunctionIndex, // invalid function 37 kInvalidFunctionIndex, // invalid function
36 kInvalidMemType // invalid memory type 38 kInvalidMemType // invalid memory type
37 }; 39 };
38 40
39 // The overall result of decoding a function or a module. 41 // The overall result of decoding a function or a module.
40 template <typename T> 42 template <typename T>
41 struct Result { 43 struct Result {
42 Result() : val(), error_code(kSuccess), start(nullptr), error_pc(nullptr) { 44 Result() : val(), error_code(kSuccess), start(nullptr), error_pc(nullptr) {
43 error_msg.Reset(nullptr); 45 error_msg.reset(nullptr);
Igor Sheludko 2016/07/25 08:56:44 Not necessary. Default constructor already does th
jochen (gone - plz use gerrit) 2016/07/25 09:14:48 done
46 }
47 Result(Result&& other) {
48 CopyFrom(other);
49 val = other.val;
Igor Sheludko 2016/07/25 08:56:44 How about using std::move(*this, other) here and i
jochen (gone - plz use gerrit) 2016/07/25 09:14:48 done. I didn't inline CopyFrom (now MoveFrom), as
50 }
51 Result& operator=(Result&& other) {
52 CopyFrom(other);
53 val = other.val;
54 return *this;
44 } 55 }
45 56
46 T val; 57 T val;
47 ErrorCode error_code; 58 ErrorCode error_code;
48 const byte* start; 59 const byte* start;
49 const byte* error_pc; 60 const byte* error_pc;
50 const byte* error_pt; 61 const byte* error_pt;
51 base::SmartArrayPointer<char> error_msg; 62 std::unique_ptr<char[]> error_msg;
52 63
53 bool ok() const { return error_code == kSuccess; } 64 bool ok() const { return error_code == kSuccess; }
54 bool failed() const { return error_code != kSuccess; } 65 bool failed() const { return error_code != kSuccess; }
55 66
56 template <typename V> 67 template <typename V>
57 void CopyFrom(Result<V>& that) { 68 void CopyFrom(Result<V>& that) {
Igor Sheludko 2016/07/25 08:56:44 Once we use unique_ptr it is no longer a CopyFrom
58 error_code = that.error_code; 69 error_code = that.error_code;
59 start = that.start; 70 start = that.start;
60 error_pc = that.error_pc; 71 error_pc = that.error_pc;
61 error_pt = that.error_pt; 72 error_pt = that.error_pt;
62 error_msg = that.error_msg; 73 error_msg.swap(that.error_msg);
63 } 74 }
75
76 private:
77 DISALLOW_COPY_AND_ASSIGN(Result);
64 }; 78 };
65 79
66 template <typename T> 80 template <typename T>
67 std::ostream& operator<<(std::ostream& os, const Result<T>& result) { 81 std::ostream& operator<<(std::ostream& os, const Result<T>& result) {
68 os << "Result = "; 82 os << "Result = ";
69 if (result.ok()) { 83 if (result.ok()) {
70 if (result.val != nullptr) { 84 if (result.val != nullptr) {
71 os << *result.val; 85 os << *result.val;
72 } else { 86 } else {
73 os << "success (no value)"; 87 os << "success (no value)";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 private: 129 private:
116 Isolate* isolate_; 130 Isolate* isolate_;
117 const char* context_; 131 const char* context_;
118 i::Handle<i::String> message_; 132 i::Handle<i::String> message_;
119 }; 133 };
120 } // namespace wasm 134 } // namespace wasm
121 } // namespace internal 135 } // namespace internal
122 } // namespace v8 136 } // namespace v8
123 137
124 #endif 138 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698