File tree Expand file tree Collapse file tree
worldedit-bukkit/adapters
adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2
adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3
adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4
adapter-1_21_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_4
adapter-1_21_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_5
adapter-1_21_6/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_6
adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1
worldedit-core/src/main/java/com/fastasyncworldedit/core/queue/implementation/chunk Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1001,19 +1001,30 @@ public boolean hasNonEmptySection(int layer) {
10011001
10021002 @ Override
10031003 @ SuppressWarnings ("unchecked" )
1004- public synchronized boolean trim (boolean aggressive ) {
1005- skyLight = new DataLayer [getSectionCount ()];
1006- blockLight = new DataLayer [getSectionCount ()];
1004+ public boolean trim (boolean aggressive ) {
1005+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1006+ if (sections == null && (!aggressive || levelChunk == null )) {
1007+ synchronized (this ) {
1008+ skyLight = new DataLayer [getSectionCount ()];
1009+ blockLight = new DataLayer [getSectionCount ()];
1010+ return !aggressive || super .trim (true );
1011+ }
1012+ }
10071013 if (aggressive ) {
10081014 sectionLock .writeLock ().lock ();
1009- sections = null ;
1010- levelChunk = null ;
1011- sectionLock .writeLock ().unlock ();
1012- return super .trim (true );
1013- } else if (sections == null ) {
1014- // don't bother trimming if there are no sections stored.
1015- return true ;
1016- } else {
1015+ try {
1016+ synchronized (this ) {
1017+ skyLight = new DataLayer [getSectionCount ()];
1018+ blockLight = new DataLayer [getSectionCount ()];
1019+ sections = null ;
1020+ levelChunk = null ;
1021+ return super .trim (true );
1022+ }
1023+ } finally {
1024+ sectionLock .writeLock ().unlock ();
1025+ }
1026+ }
1027+ synchronized (this ) {
10171028 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10181029 int layer = i - getMinSectionPosition ();
10191030 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -1002,19 +1002,30 @@ public boolean hasNonEmptySection(int layer) {
10021002
10031003 @ Override
10041004 @ SuppressWarnings ("unchecked" )
1005- public synchronized boolean trim (boolean aggressive ) {
1006- skyLight = new DataLayer [getSectionCount ()];
1007- blockLight = new DataLayer [getSectionCount ()];
1005+ public boolean trim (boolean aggressive ) {
1006+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1007+ if (sections == null && (!aggressive || levelChunk == null )) {
1008+ synchronized (this ) {
1009+ skyLight = new DataLayer [getSectionCount ()];
1010+ blockLight = new DataLayer [getSectionCount ()];
1011+ return !aggressive || super .trim (true );
1012+ }
1013+ }
10081014 if (aggressive ) {
10091015 sectionLock .writeLock ().lock ();
1010- sections = null ;
1011- levelChunk = null ;
1012- sectionLock .writeLock ().unlock ();
1013- return super .trim (true );
1014- } else if (sections == null ) {
1015- // don't bother trimming if there are no sections stored.
1016- return true ;
1017- } else {
1016+ try {
1017+ synchronized (this ) {
1018+ skyLight = new DataLayer [getSectionCount ()];
1019+ blockLight = new DataLayer [getSectionCount ()];
1020+ sections = null ;
1021+ levelChunk = null ;
1022+ return super .trim (true );
1023+ }
1024+ } finally {
1025+ sectionLock .writeLock ().unlock ();
1026+ }
1027+ }
1028+ synchronized (this ) {
10181029 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10191030 int layer = i - getMinSectionPosition ();
10201031 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -1003,19 +1003,30 @@ public boolean hasNonEmptySection(int layer) {
10031003
10041004 @ Override
10051005 @ SuppressWarnings ("unchecked" )
1006- public synchronized boolean trim (boolean aggressive ) {
1007- skyLight = new DataLayer [getSectionCount ()];
1008- blockLight = new DataLayer [getSectionCount ()];
1006+ public boolean trim (boolean aggressive ) {
1007+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1008+ if (sections == null && (!aggressive || levelChunk == null )) {
1009+ synchronized (this ) {
1010+ skyLight = new DataLayer [getSectionCount ()];
1011+ blockLight = new DataLayer [getSectionCount ()];
1012+ return !aggressive || super .trim (true );
1013+ }
1014+ }
10091015 if (aggressive ) {
10101016 sectionLock .writeLock ().lock ();
1011- sections = null ;
1012- levelChunk = null ;
1013- sectionLock .writeLock ().unlock ();
1014- return super .trim (true );
1015- } else if (sections == null ) {
1016- // don't bother trimming if there are no sections stored.
1017- return true ;
1018- } else {
1017+ try {
1018+ synchronized (this ) {
1019+ skyLight = new DataLayer [getSectionCount ()];
1020+ blockLight = new DataLayer [getSectionCount ()];
1021+ sections = null ;
1022+ levelChunk = null ;
1023+ return super .trim (true );
1024+ }
1025+ } finally {
1026+ sectionLock .writeLock ().unlock ();
1027+ }
1028+ }
1029+ synchronized (this ) {
10191030 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10201031 int layer = i - getMinSectionPosition ();
10211032 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -1037,19 +1037,30 @@ public boolean hasNonEmptySection(int layer) {
10371037
10381038 @ Override
10391039 @ SuppressWarnings ("unchecked" )
1040- public synchronized boolean trim (boolean aggressive ) {
1041- skyLight = new DataLayer [getSectionCount ()];
1042- blockLight = new DataLayer [getSectionCount ()];
1040+ public boolean trim (boolean aggressive ) {
1041+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1042+ if (sections == null && (!aggressive || levelChunk == null )) {
1043+ synchronized (this ) {
1044+ skyLight = new DataLayer [getSectionCount ()];
1045+ blockLight = new DataLayer [getSectionCount ()];
1046+ return !aggressive || super .trim (true );
1047+ }
1048+ }
10431049 if (aggressive ) {
10441050 sectionLock .writeLock ().lock ();
1045- sections = null ;
1046- levelChunk = null ;
1047- sectionLock .writeLock ().unlock ();
1048- return super .trim (true );
1049- } else if (sections == null ) {
1050- // don't bother trimming if there are no sections stored.
1051- return true ;
1052- } else {
1051+ try {
1052+ synchronized (this ) {
1053+ skyLight = new DataLayer [getSectionCount ()];
1054+ blockLight = new DataLayer [getSectionCount ()];
1055+ sections = null ;
1056+ levelChunk = null ;
1057+ return super .trim (true );
1058+ }
1059+ } finally {
1060+ sectionLock .writeLock ().unlock ();
1061+ }
1062+ }
1063+ synchronized (this ) {
10531064 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10541065 int layer = i - getMinSectionPosition ();
10551066 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -996,19 +996,30 @@ public boolean hasNonEmptySection(int layer) {
996996
997997 @ Override
998998 @ SuppressWarnings ("unchecked" )
999- public synchronized boolean trim (boolean aggressive ) {
1000- skyLight = new DataLayer [getSectionCount ()];
1001- blockLight = new DataLayer [getSectionCount ()];
999+ public boolean trim (boolean aggressive ) {
1000+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1001+ if (sections == null && (!aggressive || levelChunk == null )) {
1002+ synchronized (this ) {
1003+ skyLight = new DataLayer [getSectionCount ()];
1004+ blockLight = new DataLayer [getSectionCount ()];
1005+ return !aggressive || super .trim (true );
1006+ }
1007+ }
10021008 if (aggressive ) {
10031009 sectionLock .writeLock ().lock ();
1004- sections = null ;
1005- levelChunk = null ;
1006- sectionLock .writeLock ().unlock ();
1007- return super .trim (true );
1008- } else if (sections == null ) {
1009- // don't bother trimming if there are no sections stored.
1010- return true ;
1011- } else {
1010+ try {
1011+ synchronized (this ) {
1012+ skyLight = new DataLayer [getSectionCount ()];
1013+ blockLight = new DataLayer [getSectionCount ()];
1014+ sections = null ;
1015+ levelChunk = null ;
1016+ return super .trim (true );
1017+ }
1018+ } finally {
1019+ sectionLock .writeLock ().unlock ();
1020+ }
1021+ }
1022+ synchronized (this ) {
10121023 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10131024 int layer = i - getMinSectionPosition ();
10141025 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -996,19 +996,30 @@ public boolean hasNonEmptySection(int layer) {
996996
997997 @ Override
998998 @ SuppressWarnings ("unchecked" )
999- public synchronized boolean trim (boolean aggressive ) {
1000- skyLight = new DataLayer [getSectionCount ()];
1001- blockLight = new DataLayer [getSectionCount ()];
999+ public boolean trim (boolean aggressive ) {
1000+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1001+ if (sections == null && (!aggressive || levelChunk == null )) {
1002+ synchronized (this ) {
1003+ skyLight = new DataLayer [getSectionCount ()];
1004+ blockLight = new DataLayer [getSectionCount ()];
1005+ return !aggressive || super .trim (true );
1006+ }
1007+ }
10021008 if (aggressive ) {
10031009 sectionLock .writeLock ().lock ();
1004- sections = null ;
1005- levelChunk = null ;
1006- sectionLock .writeLock ().unlock ();
1007- return super .trim (true );
1008- } else if (sections == null ) {
1009- // don't bother trimming if there are no sections stored.
1010- return true ;
1011- } else {
1010+ try {
1011+ synchronized (this ) {
1012+ skyLight = new DataLayer [getSectionCount ()];
1013+ blockLight = new DataLayer [getSectionCount ()];
1014+ sections = null ;
1015+ levelChunk = null ;
1016+ return super .trim (true );
1017+ }
1018+ } finally {
1019+ sectionLock .writeLock ().unlock ();
1020+ }
1021+ }
1022+ synchronized (this ) {
10121023 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10131024 int layer = i - getMinSectionPosition ();
10141025 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -1004,19 +1004,30 @@ public boolean hasNonEmptySection(int layer) {
10041004
10051005 @ Override
10061006 @ SuppressWarnings ("unchecked" )
1007- public synchronized boolean trim (boolean aggressive ) {
1008- skyLight = new DataLayer [getSectionCount ()];
1009- blockLight = new DataLayer [getSectionCount ()];
1007+ public boolean trim (boolean aggressive ) {
1008+ // No need to read synchronously, if they're written immediately after, that was going to happen anyway
1009+ if (sections == null && (!aggressive || levelChunk == null )) {
1010+ synchronized (this ) {
1011+ skyLight = new DataLayer [getSectionCount ()];
1012+ blockLight = new DataLayer [getSectionCount ()];
1013+ return !aggressive || super .trim (true );
1014+ }
1015+ }
10101016 if (aggressive ) {
10111017 sectionLock .writeLock ().lock ();
1012- sections = null ;
1013- levelChunk = null ;
1014- sectionLock .writeLock ().unlock ();
1015- return super .trim (true );
1016- } else if (sections == null ) {
1017- // don't bother trimming if there are no sections stored.
1018- return true ;
1019- } else {
1018+ try {
1019+ synchronized (this ) {
1020+ skyLight = new DataLayer [getSectionCount ()];
1021+ blockLight = new DataLayer [getSectionCount ()];
1022+ sections = null ;
1023+ levelChunk = null ;
1024+ return super .trim (true );
1025+ }
1026+ } finally {
1027+ sectionLock .writeLock ().unlock ();
1028+ }
1029+ }
1030+ synchronized (this ) {
10201031 for (int i = getMinSectionPosition (); i <= getMaxSectionPosition (); i ++) {
10211032 int layer = i - getMinSectionPosition ();
10221033 if (!hasSection (i ) || super .blocks [layer ] == null ) {
Original file line number Diff line number Diff line change @@ -62,9 +62,8 @@ public synchronized boolean trim(boolean aggressive) {
6262 if (!aggressive ) {
6363 return false ;
6464 }
65- synchronized (igb ) {
66- igb .trim (true );
67- }
65+ // Don't synchronise here, let the implementation handle it
66+ igb .trim (true );
6867 }
6968 }
7069 return result ;
You can’t perform that action at this time.
0 commit comments