⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chartobytedefault.c

📁 kaffe是一个java虚拟机的源代码。里面包含了一些java例程和标准的java包。
💻 C
字号:
/* * kaffe.io.CharToByteDefault * * This class goes native because its main task is to copy chars to bytes * (i.e. System.arraycopy - incompatible arrays). It should * avoid buffer-to-buffer copying * * Copyright (c) 1998 *	Transvirtual Technologies, Inc.  All rights reserved. * * See the file "license.terms" for information on usage and redistribution  * of this file.  */#include "kaffe_io_CharToByteDefault.h"jintJava_kaffe_io_CharToByteDefault_convert( JNIEnv* env, jobject _this, 										  jcharArray fromChars, jint fromPos, jint fromLen,										  jbyteArray toBytes, jint toPos, jint toLen ){  register jint i, j;  jboolean  isCopy;  jbyte     *jb  = (*env)->GetByteArrayElements( env, toBytes, &isCopy);  int       blen = (*env)->GetArrayLength( env, toBytes);  jchar     *jc  = (*env)->GetCharArrayElements( env, fromChars, &isCopy);  int       clen = (*env)->GetArrayLength( env, fromChars);  int       n = fromPos + fromLen;  int       m = toPos + toLen;  if ( n > clen ) n = clen - fromPos;    /* be paranoid, we are native */  if ( m > blen ) m = blen - toPos;  for ( i=fromPos, j=toPos; (i<n) && (j<m); i++, j++ )	jb[j] = jc[i];  /*   * in case we have something left we cannot convert (because of missing   * 'to' buffer space), we have to store it here (via a method call to save   * the field access costs). This is very inefficient and should be avoided by   * setting the right parameter values in Java   */  if ( i < n ) {	jclass     clazz  = (*env)->GetObjectClass( env, _this);	jmethodID  mId    = (*env)->GetMethodID( env, clazz, "carry", "([CII)V");		(*env)->CallVoidMethod( env, _this, mId, fromChars, i, (n-i));  }  (*env)->ReleaseByteArrayElements( env, toBytes, jb, JNI_ABORT);  (*env)->ReleaseCharArrayElements( env, fromChars, jc, 0);  return (j - toPos);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -