From 19172132c8dc46bf8c1f83bd79eedb78cbf61bb8 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Thu, 29 Nov 2018 19:53:28 +0530 Subject: [PATCH 1/3] doc: add a note on usage scope of AliasedBuffer Explain usage context and scope of AliasedBuffer API and its function in the C++ style guide. Provide an example code. Fixes: https://github.com/nodejs/node/issues/22977 --- CPP_STYLE_GUIDE.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CPP_STYLE_GUIDE.md b/CPP_STYLE_GUIDE.md index 5099f34ea866c9..da58a67f5c5380 100644 --- a/CPP_STYLE_GUIDE.md +++ b/CPP_STYLE_GUIDE.md @@ -21,6 +21,7 @@ * [Use explicit pointer comparisons](#use-explicit-pointer-comparisons) * [Ownership and Smart Pointers](#ownership-and-smart-pointers) * [Avoid non-const references](#avoid-non-const-references) + * [Use AliasedBuffers to manipulate TypedArrays](#use-aliasedbuffers-to-manipulate-typedarrays) * [Others](#others) * [Type casting](#type-casting) * [Using `auto`](#using-auto) @@ -257,6 +258,21 @@ class ExampleClass { }; ``` +### Use AliasedBuffers to manipulate TypedArrays + +When working with typed arrays that involves direct data modification +from C++, use an AliasedBuffer when possible. The API abstraction and +the usage scope of AliasedBuffer is documented in [aliased_buffer.h][]. + +```c++ +// Create an AliasedBuffer +AliasedBuffer data; +... + +// Modify the data through natural operator semantics. +data[0] = 12345; +``` + ## Others ### Type casting @@ -382,3 +398,4 @@ even `try` and `catch` **will** break. [Run Time Type Information]: https://en.wikipedia.org/wiki/Run-time_type_information [cppref_auto_ptr]: https://en.cppreference.com/w/cpp/memory/auto_ptr [without C++ exception handling]: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html#intro.using.exception.no +[aliased_buffer.h]: https://github.com/nodejs/node/blob/master/src/aliased_buffer.h#L12 From 9960d5e8770f2163df8a210bedd50e67397f7b03 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Sun, 2 Dec 2018 22:25:48 +0530 Subject: [PATCH 2/3] fixup: apply style nits --- CPP_STYLE_GUIDE.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CPP_STYLE_GUIDE.md b/CPP_STYLE_GUIDE.md index da58a67f5c5380..65a85c16dbcaf9 100644 --- a/CPP_STYLE_GUIDE.md +++ b/CPP_STYLE_GUIDE.md @@ -260,12 +260,12 @@ class ExampleClass { ### Use AliasedBuffers to manipulate TypedArrays -When working with typed arrays that involves direct data modification -from C++, use an AliasedBuffer when possible. The API abstraction and -the usage scope of AliasedBuffer is documented in [aliased_buffer.h][]. +When working with typed arrays that involve direct data modification +from C++, use an `AliasedBuffer` when possible. The API abstraction and +the usage scope of `AliasedBuffer` is documented in [aliased_buffer.h][]. ```c++ -// Create an AliasedBuffer +// Create an AliasedBuffer. AliasedBuffer data; ... From ec0b5f618a52b7edf4c1bb19733ec3f2665fb773 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Mon, 3 Dec 2018 17:04:14 +0530 Subject: [PATCH 3/3] fixup: grammar fix --- CPP_STYLE_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CPP_STYLE_GUIDE.md b/CPP_STYLE_GUIDE.md index 65a85c16dbcaf9..b82ed7cc190ec8 100644 --- a/CPP_STYLE_GUIDE.md +++ b/CPP_STYLE_GUIDE.md @@ -262,7 +262,7 @@ class ExampleClass { When working with typed arrays that involve direct data modification from C++, use an `AliasedBuffer` when possible. The API abstraction and -the usage scope of `AliasedBuffer` is documented in [aliased_buffer.h][]. +the usage scope of `AliasedBuffer` are documented in [aliased_buffer.h][]. ```c++ // Create an AliasedBuffer.