1 |
/* String.java -- immutable character sequences; the object of string literals |
/* String.java -- immutable character sequences; the object of string literals |
2 |
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 |
Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 |
3 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
423 |
{ |
{ |
424 |
synchronized (buffer) |
synchronized (buffer) |
425 |
{ |
{ |
426 |
|
offset = 0; |
427 |
|
count = buffer.count; |
428 |
|
// Share unless buffer is 3/4 empty. |
429 |
|
if ((count << 2) < buffer.value.length) |
430 |
|
{ |
431 |
|
value = new char[count]; |
432 |
|
System.arraycopy(buffer.value, 0, value, 0, count); |
433 |
|
} |
434 |
|
else |
435 |
|
{ |
436 |
|
buffer.shared = true; |
437 |
|
value = buffer.value; |
438 |
|
} |
439 |
|
} |
440 |
|
} |
441 |
|
|
442 |
|
/** |
443 |
|
* Creates a new String using the character sequence represented by |
444 |
|
* the StringBuilder. Subsequent changes to buf do not affect the String. |
445 |
|
* |
446 |
|
* @param buffer StringBuilder to copy |
447 |
|
* @throws NullPointerException if buffer is null |
448 |
|
*/ |
449 |
|
public String(StringBuilder buffer) |
450 |
|
{ |
451 |
|
synchronized (buffer) |
452 |
|
{ |
453 |
offset = 0; |
offset = 0; |
454 |
count = buffer.count; |
count = buffer.count; |
455 |
// Share unless buffer is 3/4 empty. |
// Share unless buffer is 3/4 empty. |