Igor Murashkin | fc1ccd7 | 2015-07-30 15:11:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_RUNTIME_LAMBDA_CLOSURE_BUILDER_INL_H_ |
| 18 | #define ART_RUNTIME_LAMBDA_CLOSURE_BUILDER_INL_H_ |
| 19 | |
| 20 | #include "lambda/closure_builder.h" |
| 21 | #include <string.h> |
| 22 | |
| 23 | namespace art { |
| 24 | namespace lambda { |
| 25 | |
| 26 | template <typename T, ClosureBuilder::ShortyTypeEnum kShortyType> |
| 27 | void ClosureBuilder::CaptureVariablePrimitive(T value) { |
| 28 | static_assert(ShortyFieldTypeTraits::IsPrimitiveType<T>(), "T must be a primitive type"); |
| 29 | const size_t type_size = ShortyFieldType(kShortyType).GetStaticSize(); |
| 30 | DCHECK_EQ(type_size, sizeof(T)); |
| 31 | |
| 32 | // Copy the data while retaining the bit pattern. Strict-aliasing safe. |
| 33 | ShortyFieldTypeTraits::MaxType value_storage = 0; |
| 34 | memcpy(&value_storage, &value, sizeof(T)); |
| 35 | |
| 36 | values_.push_back(value_storage); |
| 37 | size_ += sizeof(T); |
Igor Murashkin | 6918bf1 | 2015-09-27 19:19:06 -0700 | [diff] [blame] | 38 | |
| 39 | shorty_types_ += kShortyType; |
Igor Murashkin | fc1ccd7 | 2015-07-30 15:11:09 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | } // namespace lambda |
| 43 | } // namespace art |
| 44 | |
| 45 | #endif // ART_RUNTIME_LAMBDA_CLOSURE_BUILDER_INL_H_ |