1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.7.2.1'

This commit is contained in:
gnosygnu
2016-07-10 23:35:32 -04:00
parent f5f48bb9b1
commit b333db45f8
366 changed files with 4468 additions and 3460 deletions

View File

@@ -32,10 +32,8 @@ public class Bry_bfr {
}
public Bry_bfr Mkr_rls() {
if (mkr_mgr != null) {
synchronized (mkr_mgr) {
mkr_mgr.Rls(mkr_idx);
}
synchronized (this) {
mkr_mgr.Rls(mkr_idx);
this.mkr_mgr = null;
this.mkr_idx = -1;
}
@@ -53,11 +51,11 @@ public class Bry_bfr {
rv = To_bry();
this.Clear();
if (reset > 0) Reset_if_gt(reset);
synchronized (mkr_mgr) { // SAME: Mkr_rls()
synchronized (this) { // SAME: Mkr_rls()
mkr_mgr.Rls(mkr_idx);
mkr_idx = -1; // TS: DATE:2016-07-06
mkr_mgr = null;
}
mkr_mgr = null;
mkr_idx = -1;
}
return rv;
}

View File

@@ -19,14 +19,14 @@ package gplx;
import gplx.core.primitives.*;
import gplx.core.intls.*;
public class Hash_adp_bry extends gplx.core.lists.Hash_adp_base implements Hash_adp {
private final Hash_adp_bry_itm_base proto, key_ref;
private final Hash_adp_bry_itm_base proto, key_ref;
Hash_adp_bry(Hash_adp_bry_itm_base proto) {
this.proto = proto;
this.key_ref = proto.New();
}
@Override protected Object Fetch_base(Object key) {return super.Fetch_base(key_ref.Init((byte[])key));}
@Override protected void Del_base(Object key) {super.Del_base(key_ref.Init((byte[])key));}
@Override protected boolean Has_base(Object key) {return super.Has_base(key_ref.Init((byte[])key));}
@Override protected Object Fetch_base(Object key) {synchronized (key_ref) {return super.Fetch_base(key_ref.Init((byte[])key));}} // TS: DATE:2016-07-06
@Override protected void Del_base(Object key) {synchronized (key_ref) {super.Del_base(key_ref.Init((byte[])key));}}// TS: DATE:2016-07-06
@Override protected boolean Has_base(Object key) {synchronized (key_ref) {return super.Has_base(key_ref.Init((byte[])key));}}// TS: DATE:2016-07-06
public int Get_as_int(byte[] key) {return Get_as_int(key, 0, key.length);}
public int Get_as_int(byte[] key, int bgn, int end) {
int rv = Get_as_int_or(key, bgn, end, Int_.Min_value); if (rv == Int_.Min_value) throw Err_.new_("core", "unknown key", "key", key);
@@ -42,8 +42,8 @@ public class Hash_adp_bry extends gplx.core.lists.Hash_adp_base implements Hash_
Object o = Get_by_mid(key, bgn, end);
return o == null ? or : ((Byte_obj_val)o).Val();
}
public Object Get_by_bry(byte[] src) {return super.Fetch_base(key_ref.Init(src));}
public Object Get_by_mid(byte[] src, int bgn, int end) {return super.Fetch_base(key_ref.Init(src, bgn, end));}
public Object Get_by_bry(byte[] src) {synchronized (key_ref) {return super.Fetch_base(key_ref.Init(src));}} // TS: DATE:2016-07-06
public Object Get_by_mid(byte[] src, int bgn, int end) {synchronized (key_ref) {return super.Fetch_base(key_ref.Init(src, bgn, end));}}// TS: DATE:2016-07-06
public Hash_adp_bry Add_byte_int(byte key, int val) {this.Add_base(new byte[]{key}, Int_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_bry_byte(byte[] key, byte val) {this.Add_base(key, Byte_obj_val.new_(val)); return this;}
public Hash_adp_bry Add_bry_int(byte[] key, int val) {this.Add_base(key, Int_obj_val.new_(val)); return this;}
@@ -108,7 +108,7 @@ class Hash_adp_bry_itm_cs extends Hash_adp_bry_itm_base {
}
return true;
}
public static final Hash_adp_bry_itm_cs Instance = new Hash_adp_bry_itm_cs(); Hash_adp_bry_itm_cs() {}
public static final Hash_adp_bry_itm_cs Instance = new Hash_adp_bry_itm_cs(); Hash_adp_bry_itm_cs() {}
}
class Hash_adp_bry_itm_ci_a7 extends Hash_adp_bry_itm_base {
private byte[] src; int src_bgn, src_end;
@@ -141,10 +141,10 @@ class Hash_adp_bry_itm_ci_a7 extends Hash_adp_bry_itm_base {
}
return true;
}
public static final Hash_adp_bry_itm_ci_a7 Instance = new Hash_adp_bry_itm_ci_a7(); Hash_adp_bry_itm_ci_a7() {}
public static final Hash_adp_bry_itm_ci_a7 Instance = new Hash_adp_bry_itm_ci_a7(); Hash_adp_bry_itm_ci_a7() {}
}
class Hash_adp_bry_itm_ci_u8 extends Hash_adp_bry_itm_base {
private final Gfo_case_mgr case_mgr;
private final Gfo_case_mgr case_mgr;
Hash_adp_bry_itm_ci_u8(Gfo_case_mgr case_mgr) {this.case_mgr = case_mgr;}
private byte[] src; int src_bgn, src_end;
@Override public Hash_adp_bry_itm_base New() {return new Hash_adp_bry_itm_ci_u8(case_mgr);}

View File

@@ -21,6 +21,49 @@ public class Btrie_fast_mgr {
private ByteTrieItm_fast root;
public boolean CaseAny() {return root.CaseAny();} public Btrie_fast_mgr CaseAny_(boolean v) {root.CaseAny_(v); return this;}
public int Match_pos() {return match_pos;} private int match_pos;
// Btrie_rv Match_at_w_b0_and_rls(byte[] src, int bgn, int end) {return Match_at_w_b0_and_rls(src[bgn], src, bgn, end);}
// Btrie_rv Match_at_w_b0_and_rls(byte b, byte[] src, int bgn_pos, int src_end) {
// Btrie_rv rv = ((Btrie_rv)Btrie_rv.Pool__mgr.Get_safe());
// Match_at_w_b0(rv, b, src, bgn_pos, src_end);
// return rv;
// }
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int src_end) {
Object rv_obj = null;
int rv_pos = bgn_pos;
ByteTrieItm_fast nxt = root.Ary_find(b);
if (nxt == null) { // nxt does not have b; return rv;
rv.Init(rv_pos, rv_obj);
return rv_obj;
}
int cur_pos = bgn_pos + 1;
ByteTrieItm_fast cur = root;
while (true) {
if (nxt.Ary_is_empty()) { // nxt is leaf; return nxt.Val() (which should be non-null)
rv_obj = nxt.Val();
rv.Init(cur_pos, rv_obj);
return rv_obj;
}
Object nxt_val = nxt.Val();
if (nxt_val != null) { // nxt is node; cache rv (in case of false match)
rv_pos = cur_pos;
rv_obj = nxt_val;
}
if (cur_pos == src_end) { // eos; exit
rv.Init(rv_pos, rv_obj);
return rv_obj;
}
b = src[cur_pos];
cur = nxt;
nxt = cur.Ary_find(b);
if (nxt == null) {
rv.Init(rv_pos, rv_obj);
return rv_obj;
}
++cur_pos;
}
}
public Object Match_exact(byte[] src, int bgn_pos, int end_pos) {
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;

View File

@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.core.btries; import gplx.*; import gplx.core.*;
import gplx.core.threads.poolables.*;
public class Btrie_rv implements Gfo_poolable_itm {
public class Btrie_rv {
public Object Obj() {return obj;} private Object obj;
public int Pos() {return pos;} private int pos;
public Btrie_rv Init(int pos, Object obj) {
@@ -25,7 +25,4 @@ public class Btrie_rv implements Gfo_poolable_itm {
this.pos = pos;
return this;
}
public void Pool__rls () {pool_mgr.Rls_fast(pool_idx);} private Gfo_poolable_mgr pool_mgr; private int pool_idx;
public Gfo_poolable_itm Pool__make (Gfo_poolable_mgr mgr, int idx, Object[] args) {Btrie_rv rv = new Btrie_rv(); rv.pool_mgr = mgr; rv.pool_idx = idx; return rv;}
}

View File

@@ -79,7 +79,9 @@ public class Btrie_slim_itm {
Btrie_slim_itm rv = new Btrie_slim_itm(b, val, case_any);
ary[ary_len] = rv;
ary_len = new_len;
ByteHashItm_sorter.Instance.Sort(ary, ary_len);
synchronized (ByteHashItm_sorter.Instance) {// TS: DATE:2016-07-06
ByteHashItm_sorter.Instance.Sort(ary, ary_len);
}
return rv;
}
public void Ary_del(byte b) {

View File

@@ -18,29 +18,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.core.btries; import gplx.*; import gplx.core.*;
import gplx.core.primitives.*; import gplx.core.threads.poolables.*;
public class Btrie_slim_mgr implements Btrie_mgr {
private static Gfo_poolable_mgr pool_rv = Gfo_poolable_mgr.New_rlsable(new Btrie_rv(), Object_.Ary_empty, 0, 1024);
Btrie_slim_mgr(boolean case_match) {root = new Btrie_slim_itm(Byte_.Zero, null, !case_match);} private Btrie_slim_itm root;
public int Count() {return count;} private int count;
public int Match_pos() {return match_pos;} private int match_pos;
public Btrie_rv Match_at(byte[] src, int bgn, int end) {return bgn < end ? Match_at_w_b0(src[bgn], src, bgn, end) : null;} // handle out of bounds gracefully; EX: Match_bgn("abc", 3, 3) should return null not fail
public Btrie_rv Match_at_w_b0(byte b, byte[] src, int bgn_pos, int src_end) {
public Object Match_at(Btrie_rv rv, byte[] src, int bgn_pos, int end_pos) {return bgn_pos < end_pos ? Match_at_w_b0(rv, src[bgn_pos], src, bgn_pos, end_pos) : null;} // handle out of bounds gracefully; EX: Match_bgn("abc", 3, 3) should return null not fail
public Object Match_at_w_b0(Btrie_rv rv, byte b, byte[] src, int bgn_pos, int src_end) {
Object rv_obj = null;
int rv_pos = bgn_pos;
int cur_pos = bgn_pos;
Btrie_slim_itm cur = root;
while (true) {
Btrie_slim_itm nxt = cur.Ary_find(b);
if (nxt == null)
return ((Btrie_rv)pool_rv.Get_safe()).Init(cur_pos, rv_obj); // nxt does not hav b; return rv_obj;
if (nxt == null) {
rv.Init(cur_pos, rv_obj); // nxt does not hav b; return rv_obj;
return rv_obj;
}
++cur_pos;
if (nxt.Ary_is_empty()) {
return ((Btrie_rv)pool_rv.Get_safe()).Init(cur_pos, nxt.Val()); // nxt is leaf; return nxt.Val() (which should be non-null)
rv_obj = nxt.Val();
rv.Init(cur_pos, rv_obj); // nxt is leaf; return nxt.Val() (which should be non-null)
return rv_obj;
}
Object nxt_val = nxt.Val();
if (nxt_val != null) {rv_pos = cur_pos; rv_obj = nxt_val;} // nxt is node; cache rv_obj (in case of false match)
if (cur_pos == src_end)
return ((Btrie_rv)pool_rv.Get_safe()).Init(rv_pos, rv_obj); // increment cur_pos and exit if src_end
if (nxt_val != null) {rv_pos = cur_pos; rv_obj = nxt_val;} // nxt is node; cache rv_obj (in case of false match)
if (cur_pos == src_end) {
rv.Init(rv_pos, rv_obj); // increment cur_pos and exit if src_end
return rv_obj;
}
b = src[cur_pos];
cur = nxt;
}
@@ -51,7 +56,7 @@ public class Btrie_slim_mgr implements Btrie_mgr {
Object rv = Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos);
return rv == null ? null : match_pos - bgn_pos == end_pos - bgn_pos ? rv : null;
}
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return bgn_pos < end_pos ? Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos) : null;} // handle out of bounds gracefully; EX: Match_bgn("abc", 3, 3) should return null not fail
public Object Match_bgn(byte[] src, int bgn_pos, int end_pos) {return bgn_pos < end_pos ? Match_bgn_w_byte(src[bgn_pos], src, bgn_pos, end_pos) : null;} // handle out of bounds gracefully; EX: Match_bgn("abc", 3, 3) should return null not fail
public Object Match_bgn_w_byte(byte b, byte[] src, int bgn_pos, int src_end) {
Object rv = null; int cur_pos = match_pos = bgn_pos;
Btrie_slim_itm cur = root;

View File

@@ -52,7 +52,7 @@ public class Env_ {
public static int TickCount_elapsed_in_frac(long time_bgn) {return (int)(Env_.TickCount() - time_bgn);}
public static long TickCount_Test = -1; // in milliseconds
public static void TickCount_normal() {TickCount_Test = -1;}
public static long System_cpu_count() {return Runtime.getRuntime().availableProcessors();}
public static int System_cpu_count() {return Runtime.getRuntime().availableProcessors();}
public static long System_memory_max() {return Runtime.getRuntime().maxMemory();}
public static long System_memory_total() {return Runtime.getRuntime().totalMemory();}
public static long System_memory_free() {return Runtime.getRuntime().freeMemory();}

View File

@@ -232,6 +232,7 @@ class Io_stream_rdr_zip implements Io_stream_rdr {
class Io_stream_rdr_gzip extends Io_stream_rdr_base {
@Override public byte Tid() {return Io_stream_.Tid_gzip;}
@Override public int Read(byte[] bry, int bgn, int len) {
synchronized (this) {
try {
int total_read = 0;
while (true) { // NOTE: the gz stream reads partially; (request 100; only get back 10); keep reading until entire bfr is full or -1
@@ -247,6 +248,7 @@ class Io_stream_rdr_gzip extends Io_stream_rdr_base {
catch (Exception e) {
throw Err_.new_exc(e, "io", "read failed", "bgn", bgn, "len", len);
}
}
}
@Override public java.io.InputStream Wrap_stream(java.io.InputStream stream) {
try {return new java.util.zip.GZIPInputStream(stream);}

View File

@@ -34,7 +34,11 @@ public class Io_zip_compress_cmd__jre {
Io_url src_url = src_urls[i];
java.util.zip.ZipEntry trg_entry = new java.util.zip.ZipEntry(src_url.NameAndExt());
try {trg_stream.putNextEntry(trg_entry);}
catch (Exception e) {throw Err_.new_exc(e, "io", "zip entry failed", "url", src_url.Raw());}
catch (Exception e) {
try {trg_stream.close();}
catch (IOException e1) {}
throw Err_.new_exc(e, "io", "zip entry failed", "url", src_url.Raw());
}
FileInputStream src_stream = null;
try {src_stream = new FileInputStream(new File(src_url.Raw()));}
catch (Exception e) {throw Err_.new_exc(e, "io", "src open failed", "url", src_url.Raw());}
@@ -55,8 +59,7 @@ public class Io_zip_compress_cmd__jre {
}
}
try {
trg_stream.closeEntry();
trg_stream.close();
trg_stream.closeEntry();
src_stream.close();
}
catch (Exception e) {throw Err_.new_exc(e, "io", "trg close entry failed", "url", src_url.Raw());}

View File

@@ -21,10 +21,12 @@ public class Gfo_msg_log {
public int Ary_len() {return ary_idx;}
public Gfo_msg_data Ary_get(int i) {return ary[i];}
public Gfo_msg_log Clear() {
for (int i = 0; i < ary_idx; i++)
ary[i].Clear();
ary_idx = 0;
return this;
synchronized (this) { // TS: DATE:2016-07-06
for (int i = 0; i < ary_idx; i++)
ary[i].Clear();
ary_idx = 0;
return this;
}
}
public Gfo_msg_log Add_str_warn_key_none(String grp, String itm, byte[] src, int pos) {return Add_str(Gfo_msg_itm_.Cmd_warn, grp, itm, null, src, pos, pos + 1, null);}
public Gfo_msg_log Add_str_warn_key_none(String grp, String itm, byte[] src, int bgn, int end) {return Add_str(Gfo_msg_itm_.Cmd_warn, grp, itm, null, src, bgn, end, null);}
@@ -33,16 +35,20 @@ public class Gfo_msg_log {
public Gfo_msg_log Add_str_warn_fmt_none(String grp, String itm, String fmt, byte[] src, int bgn, int end) {return Add_str(Gfo_msg_itm_.Cmd_warn, grp, itm, fmt , src, bgn, end, null);}
public Gfo_msg_log Add_str_warn_fmt_many(String grp, String itm, String fmt, Object... vals) {return Add_str(Gfo_msg_itm_.Cmd_warn, grp, itm, fmt , Bry_.Empty, -1, -1, vals);}
Gfo_msg_log Add_str(byte cmd, String owner_key, String itm, String fmt, byte[] src, int bgn, int end, Object[] vals) {
if (ary_idx >= ary_max) ary_expand();
ary[ary_idx++] = root.Data_new_many(cmd, src, bgn, end, owner_key, itm, fmt, vals);
return this;
synchronized (this) { // TS: DATE:2016-07-06
if (ary_idx >= ary_max) ary_expand();
ary[ary_idx++] = root.Data_new_many(cmd, src, bgn, end, owner_key, itm, fmt, vals);
return this;
}
}
public Gfo_msg_log Add_itm_none(Gfo_msg_itm itm, byte[] src, int bgn, int end) {return Add_itm(itm, src, bgn, end, null);}
public Gfo_msg_log Add_itm_many(Gfo_msg_itm itm, byte[] src, int bgn, int end, Object... val_ary) {return Add_itm(itm, src, bgn, end, val_ary);}
Gfo_msg_log Add_itm(Gfo_msg_itm itm, byte[] src, int bgn, int end, Object[] vals) {
if (ary_idx >= ary_max) ary_expand();
ary[ary_idx++] = root.Data_new_many(itm, src, bgn, end, vals);
return this;
synchronized (this) { // TS: DATE:2016-07-06
if (ary_idx >= ary_max) ary_expand();
ary[ary_idx++] = root.Data_new_many(itm, src, bgn, end, vals);
return this;
}
}
void ary_expand() {
int new_max = ary_max == 0 ? 2 : ary_max * 2;

View File

@@ -99,6 +99,7 @@ public class Gftest {
throw Err_.new_wo_type(bfr.To_str_and_clear());
}
public static void Eq__bool_y(boolean actl) {Eq__bool(Bool_.Y, actl, null);}
public static void Eq__bool_y(boolean actl, String msg_fmt, Object... msg_args) {Eq__bool(Bool_.Y, actl, msg_fmt, msg_args);}
public static void Eq__bool(boolean expd, boolean actl) {Eq__bool(expd, actl, null);}
public static void Eq__bool(boolean expd, boolean actl, String msg_fmt, Object... msg_args) {
if (expd == actl) return;

View File

@@ -55,7 +55,7 @@ public class Gfo_poolable_mgr implements Gfo_memory_itm {
}
return rv;
}
public void Rls_safe(int idx) {synchronized (thread_lock) {Rls_safe(idx);}}
public void Rls_safe(int idx) {synchronized (thread_lock) {Rls_fast(idx);}}
public void Rls_fast(int idx) {
if (idx == -1) throw Err_.new_wo_type("rls called on poolable that was not created by pool_mgr");
int pool_idx = pool_nxt - 1;