@@ -4271,6 +4271,18 @@ public static String valueOf(double d) {
4271
4271
// return Double.toString(d);
4272
4272
}
4273
4273
4274
+ /**
4275
+ * Pool of strings used by the {@code String}.intern model.
4276
+ */
4277
+ static String [] cproverInternPool = null ;
4278
+
4279
+ /**
4280
+ * Number of elements stored in the pool for {@code String.intern} pool.
4281
+ * This can be smaller than {@code cproverInternPool.length} which
4282
+ * represents the capacity of the array and is fixed for each execution.
4283
+ */
4284
+ static int cproverInternPoolSize = 0 ;
4285
+
4274
4286
/**
4275
4287
* Returns a canonical representation for the string object.
4276
4288
* <p>
@@ -4294,11 +4306,29 @@ public static String valueOf(double d) {
4294
4306
* @return a string that has the same contents as this string, but is
4295
4307
* guaranteed to be from a pool of unique strings.
4296
4308
*
4297
- * @diffblue.noSupport
4309
+ * @diffblue.limitedSupport literal strings and string-valued constant
4310
+ * expressions are not interned.
4298
4311
*/
4312
+ // DIFFBLUE MODEL LIBRARY
4299
4313
// public native String intern();
4300
4314
public String intern () {
4301
- CProver .notModelled ();
4302
- return CProver .nondetWithoutNullForNotModelled ();
4315
+ // Initialize the pool if needed
4316
+ if (cproverInternPool == null ) {
4317
+ int capacity = CProver .nondetInt ();
4318
+ CProver .assume (capacity > 0 );
4319
+ cproverInternPool = new String [capacity ];
4320
+ cproverInternPool [0 ] = this ;
4321
+ return this ;
4322
+ }
4323
+ // Look for an entry in the pool equal to `this`
4324
+ for (int i = 0 ; i < cproverInternPoolSize ; ++i ) {
4325
+ if (CProverString .equals (cproverInternPool [i ], this )) {
4326
+ return cproverInternPool [i ];
4327
+ }
4328
+ }
4329
+ // Add `this` to the pool
4330
+ CProver .assume (cproverInternPool .length > cproverInternPoolSize );
4331
+ cproverInternPool [cproverInternPoolSize ++] = this ;
4332
+ return this ;
4303
4333
}
4304
4334
}
0 commit comments