Skip to content

Commit b217cf5

Browse files
committed
Revise comments
1 parent e674a83 commit b217cf5

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

rosidl_gen/templates/message.dot

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function isTypedArrayType(type) {
157157
return typedArrayType.indexOf(type.type.toLowerCase()) !== -1;
158158
}
159159

160-
const usePlainTypedArray = isTypedArrayType(it.spec.baseType);
160+
const willUseTypedArray = isTypedArrayType(it.spec.baseType);
161161
const currentTypedArray = getTypedArrayName(it.spec.baseType);
162162
const currentTypedArrayElementType = getTypedArrayElementName(it.spec.baseType);
163163

@@ -219,7 +219,7 @@ function extractMemberNames(fields) {
219219
}
220220
}}
221221

222-
{{? usePlainTypedArray}}
222+
{{? willUseTypedArray}}
223223
const rclnodejs = require('bindings')('rclnodejs');
224224
{{?}}
225225
const ref = require('@rclnodejs/ref-napi');
@@ -257,7 +257,7 @@ const {{=refObjectType}} = StructType({
257257

258258
const {{=refArrayType}} = ArrayType({{=refObjectType}});
259259
const {{=refObjectArrayType}} = StructType({
260-
{{? usePlainTypedArray}}
260+
{{? willUseTypedArray}}
261261
data: ref.refType(ref.types.{{=currentTypedArrayElementType}}),
262262
{{??}}
263263
data: {{=refArrayType}},
@@ -377,7 +377,7 @@ class {{=objectWrapper}} {
377377
}
378378
}
379379
{{??}}
380-
{{/* For non-typed array like int64/uint64/bool. */}}
380+
{{/* For non-TypedArray like int64/uint64/bool. */}}
381381
this._refObject.{{=field.name}} = this._{{=field.name}}Array;
382382
{{?}}
383383
{{?? field.type.isArray && field.type.isPrimitiveType && isTypedArrayType(field.type) && field.type.isFixedSizeArray}}
@@ -439,7 +439,7 @@ class {{=objectWrapper}} {
439439
this._{{=field.name}}Array[index] = refObject.{{=field.name}}[index].data;
440440
}
441441
{{??}}
442-
{{/* For non-typed array like int64/uint64/bool. */}}
442+
{{/* For non-TypedArray like int64/uint64/bool. */}}
443443
this._{{=field.name}}Array = refObject.{{=field.name}}.toArray();
444444
{{?}}
445445
{{?? field.type.isArray && field.type.isPrimitiveType && !isTypedArrayType(field.type)}}
@@ -472,9 +472,8 @@ class {{=objectWrapper}} {
472472
{{? field.type.isArray && !field.type.isFixedSizeArray}}
473473
if (refObject.{{=field.name}}.size != 0) {
474474
{{=getWrapperNameByType(field.type)}}.ArrayType.freeArray(refObject.{{=field.name}});
475-
if ({{=getWrapperNameByType(field.type)}}.ArrayType.useTypedArray) {
476-
{{/* Do nothing, the v8 will take the ownership of the ArrayBuffer used by the typed array. */}}
477-
} else {
475+
{{/* We don't need to free the memory for TypedArray objects, because v8 takes the ownership of it. */}}
476+
if (!{{=getWrapperNameByType(field.type)}}.ArrayType.useTypedArray) {
478477
deallocator.freeStructMember(refObject.{{=field.name}}, {{=getWrapperNameByType(field.type)}}.refObjectArrayType, 'data');
479478
}
480479
}
@@ -630,7 +629,7 @@ class {{=arrayWrapper}} {
630629
}
631630

632631
fill(values) {
633-
{{? usePlainTypedArray}}
632+
{{? willUseTypedArray}}
634633
if (Array.isArray(values)) {
635634
{{/* Convert to TypedArray. */}}
636635
this._wrappers = new {{=currentTypedArray}}(values);
@@ -662,7 +661,7 @@ class {{=arrayWrapper}} {
662661
{{/* Put all data currently stored in `this._wrappers` into `this._refObject`. */}}
663662
freeze(own) {
664663
{{/* When it's a TypedArray: no need to copy to `this._refArray`. */}}
665-
{{? !usePlainTypedArray}}
664+
{{? !willUseTypedArray}}
666665
this._wrappers.forEach((wrapper, index) => {
667666
wrapper.freeze(own);
668667
this._refArray[index] = wrapper.refObject;
@@ -675,7 +674,7 @@ class {{=arrayWrapper}} {
675674
if (this._refObject.capacity === 0) {
676675
this._refObject.data = null
677676
} else {
678-
{{? usePlainTypedArray}}
677+
{{? willUseTypedArray}}
679678
const buffer = Buffer.from(new Uint8Array(this._wrappers.buffer));
680679
this._refObject.data = buffer;
681680
{{??}}
@@ -722,7 +721,7 @@ class {{=arrayWrapper}} {
722721
if (size < 0) {
723722
throw new RangeError('Invalid argument: should provide a positive number');
724723
}
725-
{{? usePlainTypedArray}}
724+
{{? willUseTypedArray}}
726725
this._refArray = undefined;
727726
{{??}}
728727
this._refArray = new {{=refArrayType}}(size);
@@ -732,7 +731,7 @@ class {{=arrayWrapper}} {
732731
this._refObject.size = size;
733732
this._refObject.capacity = size;
734733

735-
{{? usePlainTypedArray}}
734+
{{? willUseTypedArray}}
736735
this._wrappers = new {{=currentTypedArray}}(size);
737736
{{??}}
738737
this._wrappers = new Array();
@@ -746,9 +745,9 @@ class {{=arrayWrapper}} {
746745
copyRefObject(refObject) {
747746
this._refObject = refObject;
748747

749-
{{? usePlainTypedArray}}
748+
{{? willUseTypedArray}}
750749
const byteLen = refObject.size * ref.types.{{=currentTypedArrayElementType}}.size;
751-
{{/* An ArrayBuffer object doesn't hold the ownership of memory block starting from address. */}}
750+
{{/* An ArrayBuffer object doesn't hold the ownership of memory block starting from address for TypedArray. */}}
752751
const arrayBuffer = refObject.data.length !== 0 ?
753752
rclnodejs.createArrayBufferFromAddress(refObject.data.hexAddress(), byteLen) :
754753
Buffer.alloc(0);
@@ -769,20 +768,19 @@ class {{=arrayWrapper}} {
769768
}
770769

771770
this._resize(other.size);
772-
{{? usePlainTypedArray}}
771+
{{? willUseTypedArray}}
773772
this._wrappers = other._wrappers.slice();
774773
{{??}}
775-
{{/* Deep copy for the type of Array. */}}
774+
{{/* Deep copy for non-TypedArray. */}}
776775
other._wrappers.forEach((wrapper, index) => {
777776
this._wrappers[index].copy(wrapper);
778777
});
779778
{{?}}
780779
}
781780

782781
static freeArray(refObject) {
783-
{{? usePlainTypedArray}}
784-
{{/* For TypedArray, `.data` will be 'free()'-ed in parent struct. */}}
785-
{{??}}
782+
{{/* We don't need to free the memory for TypedArray objects, because v8 takes the ownership of it. */}}
783+
{{? !willUseTypedArray}}
786784
let refObjectArray = refObject.data;
787785
refObjectArray.length = refObject.size;
788786
for (let index = 0; index < refObject.size; index++) {
@@ -800,7 +798,7 @@ class {{=arrayWrapper}} {
800798
}
801799

802800
static get useTypedArray() {
803-
return {{=usePlainTypedArray}};
801+
return {{=willUseTypedArray}};
804802
}
805803

806804
get classType() {

0 commit comments

Comments
 (0)