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

Side by Side Diff: mojo/public/cpp/bindings/lib/bindings_internal.cc

Issue 2202023005: Mojo C++ bindings: inline pointer encoding/decoding/validating functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_inline_data_view
Patch Set: . Created 4 years, 4 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/public/cpp/bindings/lib/bindings_internal.h"
6
7 namespace mojo {
8 namespace internal {
9
10 namespace {
11
12 const size_t kAlignment = 8;
13
14 template <typename T>
15 T AlignImpl(T t) {
16 return t + (kAlignment - (t % kAlignment)) % kAlignment;
17 }
18
19 } // namespace
20
21 size_t Align(size_t size) {
22 return AlignImpl(size);
23 }
24
25 char* AlignPointer(char* ptr) {
26 return reinterpret_cast<char*>(AlignImpl(reinterpret_cast<uintptr_t>(ptr)));
27 }
28
29 bool IsAligned(const void* ptr) {
30 return !(reinterpret_cast<uintptr_t>(ptr) % kAlignment);
31 }
32
33 void EncodePointer(const void* ptr, uint64_t* offset) {
34 if (!ptr) {
35 *offset = 0;
36 return;
37 }
38
39 const char* p_obj = reinterpret_cast<const char*>(ptr);
40 const char* p_slot = reinterpret_cast<const char*>(offset);
41 DCHECK(p_obj > p_slot);
42
43 *offset = static_cast<uint64_t>(p_obj - p_slot);
44 }
45
46 } // namespace internal
47 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.h ('k') | mojo/public/cpp/bindings/lib/validation_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698