2727import java .util .LinkedList ;
2828import java .util .List ;
2929
30+ import nu .validator .htmlparser .annotation .CppInlineLength ;
3031import nu .validator .htmlparser .annotation .Inline ;
3132import nu .validator .htmlparser .annotation .Local ;
33+ import nu .validator .htmlparser .annotation .StaticLocal ;
34+ import nu .validator .htmlparser .annotation .WeakLocal ;
3235import nu .validator .htmlparser .annotation .NoLength ;
3336import nu .validator .htmlparser .annotation .NsUri ;
3437import nu .validator .htmlparser .annotation .Prefix ;
@@ -66,6 +69,8 @@ public final class AttributeName
6669 // ]NOCPP]
6770 };
6871
72+ // CPPONLY: static final @NoLength @StaticLocal String[] SAME_LOCAL_NULL = { null, null, null, };
73+
6974 /**
7075 * An array that has no namespace for the HTML mode but the XMLNS namespace
7176 * for the SVG and MathML modes.
@@ -181,9 +186,9 @@ public final class AttributeName
181186 * the name for the SVG mode
182187 * @return the initialized name array
183188 */
184- private static @ NoLength @ Local String [] SVG_DIFFERENT (@ Local String name ,
185- @ Local String camel ) {
186- @ NoLength @ Local String [] arr = new String [4 ];
189+ private static @ NoLength @ StaticLocal String [] SVG_DIFFERENT (@ StaticLocal String name ,
190+ @ StaticLocal String camel ) {
191+ @ NoLength @ StaticLocal String [] arr = new String [4 ];
187192 arr [0 ] = name ;
188193 arr [1 ] = name ;
189194 arr [2 ] = camel ;
@@ -203,9 +208,9 @@ public final class AttributeName
203208 * the name for the MathML mode
204209 * @return the initialized name array
205210 */
206- private static @ NoLength @ Local String [] MATH_DIFFERENT (@ Local String name ,
207- @ Local String camel ) {
208- @ NoLength @ Local String [] arr = new String [4 ];
211+ private static @ NoLength @ StaticLocal String [] MATH_DIFFERENT (@ StaticLocal String name ,
212+ @ StaticLocal String camel ) {
213+ @ NoLength @ StaticLocal String [] arr = new String [4 ];
209214 arr [0 ] = name ;
210215 arr [1 ] = camel ;
211216 arr [2 ] = name ;
@@ -225,9 +230,9 @@ public final class AttributeName
225230 * the name for the SVG and MathML modes
226231 * @return the initialized name array
227232 */
228- private static @ NoLength @ Local String [] COLONIFIED_LOCAL (
229- @ Local String name , @ Local String suffix ) {
230- @ NoLength @ Local String [] arr = new String [4 ];
233+ private static @ NoLength @ StaticLocal String [] COLONIFIED_LOCAL (
234+ @ StaticLocal String name , @ StaticLocal String suffix ) {
235+ @ NoLength @ StaticLocal String [] arr = new String [4 ];
231236 arr [0 ] = name ;
232237 arr [1 ] = suffix ;
233238 arr [2 ] = suffix ;
@@ -244,8 +249,8 @@ public final class AttributeName
244249 * the name
245250 * @return the initialized name array
246251 */
247- static @ NoLength @ Local String [] SAME_LOCAL (@ Local String name ) {
248- @ NoLength @ Local String [] arr = new String [4 ];
252+ static @ NoLength @ StaticLocal String [] SAME_LOCAL (@ StaticLocal String name ) {
253+ @ NoLength @ StaticLocal String [] arr = new String [4 ];
249254 arr [0 ] = name ;
250255 arr [1 ] = name ;
251256 arr [2 ] = name ;
@@ -376,17 +381,20 @@ public final class AttributeName
376381 /**
377382 * The namespaces indexable by mode.
378383 */
379- private final @ NsUri @ NoLength String [] uri ;
384+ private final @ CppInlineLength ( 3 ) @ NsUri @ NoLength String [] uri ;
380385
381386 /**
382387 * The local names indexable by mode.
388+ *
389+ * These are weak because they're either all static, or
390+ * all the same, in wich case we just need to take one reference.
383391 */
384- private final @ Local @ NoLength String [] local ;
392+ private final @ CppInlineLength ( 3 ) @ WeakLocal @ NoLength String [] local ;
385393
386394 /**
387395 * The prefixes indexably by mode.
388396 */
389- private final @ Prefix @ NoLength String [] prefix ;
397+ private final @ CppInlineLength ( 3 ) @ Prefix @ NoLength String [] prefix ;
390398
391399 // CPPONLY: private final boolean custom;
392400
@@ -416,7 +424,7 @@ public final class AttributeName
416424 * whether this is an xmlns attribute
417425 */
418426 private AttributeName (@ NsUri @ NoLength String [] uri ,
419- @ Local @ NoLength String [] local , @ Prefix @ NoLength String [] prefix
427+ @ StaticLocal @ NoLength String [] local , @ Prefix @ NoLength String [] prefix
420428 // [NOCPP[
421429 , int flags
422430 // ]NOCPP]
@@ -429,11 +437,12 @@ private AttributeName(@NsUri @NoLength String[] uri,
429437 this .flags = flags ;
430438 // ]NOCPP]
431439 // CPPONLY: this.custom = false;
440+ // CPPONLY: Portability.deleteArray(local);
432441 }
433442
434443 // CPPONLY: public AttributeName() {
435- // CPPONLY: this.uri = AttributeName. ALL_NO_NS;
436- // CPPONLY: this.local = AttributeName.SAME_LOCAL(null) ;
444+ // CPPONLY: this.uri = ALL_NO_NS;
445+ // CPPONLY: this.local = SAME_LOCAL_NULL ;
437446 // CPPONLY: this.prefix = ALL_NO_PREFIX;
438447 // CPPONLY: this.custom = true;
439448 // CPPONLY: }
@@ -444,6 +453,8 @@ private AttributeName(@NsUri @NoLength String[] uri,
444453 // CPPONLY:
445454 // CPPONLY: @Inline public void setNameForNonInterned(@Local String name) {
446455 // CPPONLY: assert custom;
456+ // CPPONLY: Portability.addrefIfNonNull(name);
457+ // CPPONLY: Portability.releaseIfNonNull(local[0]);
447458 // CPPONLY: local[0] = name;
448459 // CPPONLY: local[1] = name;
449460 // CPPONLY: local[2] = name;
@@ -458,28 +469,28 @@ private AttributeName(@NsUri @NoLength String[] uri,
458469 * whether to check ncnameness
459470 * @return an <code>AttributeName</code>
460471 */
461- static AttributeName createAttributeName (@ Local String name
462472 // [NOCPP[
473+ static AttributeName createAttributeName (@ Local String name
463474 , boolean checkNcName
464- // ]NOCPP]
465475 ) {
466- // [NOCPP[
467476 int flags = NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG ;
468477 if (name .startsWith ("xmlns:" )) {
469478 flags = IS_XMLNS ;
470479 } else if (checkNcName && !NCName .isNCName (name )) {
471480 flags = 0 ;
472481 }
473- // ]NOCPP]
474482 return new AttributeName (AttributeName .ALL_NO_NS ,
475483 AttributeName .SAME_LOCAL (name ), ALL_NO_PREFIX , flags );
476484 }
485+ // ]NOCPP]
477486
478487 /**
479488 * The C++ destructor.
480489 */
481490 @ SuppressWarnings ("unused" ) private void destructor () {
482- Portability .deleteArray (local );
491+ // CPPONLY: if (custom) {
492+ // CPPONLY: Portability.releaseIfNonNull(local[0]);
493+ // CPPONLY: }
483494 }
484495
485496 // [NOCPP[
0 commit comments